Jump to content
Larry Ullman's Book Forums

elgato454

Members
  • Posts

    10
  • Joined

  • Last visited

Posts posted by elgato454

  1. The root folder is this:

     

    C:\xampp\htdocs

     

    Originally, I had my temporary files stored in the default folder; but, like I said, I set two temp file folders up inside my directory.  The first one is:

     

    C:\xampp\htdocs\phpmysql\php-work\uploads

     

    The second one is the one I have listed in the previous post:

     

    C:\xampp\htdocs\phpmysql\php-work\ch11\uploads

     

    I keep going back and forth between folders and, for some reason, I'm still not getting the picture to display.

     

    Does this help?

  2. Good Afternoon!

     

    I'm having trouble executing Script 11.4 in Chapter 11.  The code for Script 11.2 reads:

    <?php  #  Script 11.2 - upload-image.php
     
    // Check if the form has been submitted:
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Check for an uploaded file:
    if (isset($_FILES['upload'])) {
    // Validate the type.  Should be JPEG or PNG.
    $allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPG','image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');
    if (in_array($_FILES['upload']['type'], $allowed)) {
    // Move the file over.
    if(move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/{$_FILES['upload']['name']}")) {
    echo '<p><em>The file has been uploaded!</em></p>';
    } // End of move IF.
    else {
    // Invalid type
    echo '<p class="error">Please upload a JPEG or PNG image.</p>';
    }
    } // End of isset($_FILES['upload'] IF.
     
    // Check for an error:
    if ($_FILES['upload']['error'] > 0) {
    echo '<p class="error">The file could not be uploaded because: <strong>';
     
    // Print a message based upon the error.
    switch($_FILES['upload']['error']) {
    case 1:
    print 'The file exceeds the upload_max_file size setting in php.ini.';
    break;
    case 2:
    print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.';
    break;
    case 3:
    print 'The file was only partially uploaded.';
    break;
    case 4:
    print 'No file was uploaded.';
    break;
    case 6:
    print 'No temporary folder was available.';
    break;
    case 7:
    print 'Unable to write to the disk.';
    break;
    case 8:
    print 'File upload stopped.';
    break;
    default:
    print 'A system error occured.';
    break;
    } // End of error IF.
     
    // Delete the file as if it still exists:
    if (file_exists($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']) )
    {
    uplink($_FILES['upload']['tmp_name']);
    }
     
    } // End of the submitted conditional
    }
    }
     
    ?>
     
    This is my Script 11.3:
     
    function create_window (image, width, height) {
    // Add some pixels to the width and height:
    width = width + 10;
    height = height + 10;
     
    // If the window is already open,
    // resize it to the new dimensions:
    if (window.popup && !window.popup.closed) {
    window.popup.resizeTo(width,height);
    }
     
    // Set the window properties
    var specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes, left=0, top=0, width=" + width + ", height=" + height;
     
    // Set the URL:
    var url = "show_image.php?image=" + image;
     
    // Create the popup window:
    popup = window.open(url, "ImageWindow", specs);
    popup.focus();
    }
     
    Finally, this is Script 11.4:
     
    <?php # Script 11.4 - images.php
    // This script lists the images in the uploads directory.
     
    $dir = '../uploads'; // Define the directory to view.
     
    $files = scandir($dir); // Read all the images into an array.
     
    // Display each image caption as a link to the JavaScript function:
    foreach ($files as $image) {
     
    if (substr($image, 0, 1) != '.') { // Ignore anything starting with a period.
     
    // Get the image's size in pixels:
    $image_size = getimagesize ("$dir/$image");
     
    // Make the image's name URL-safe:
    $image_name = urlencode($image);
     
    // Print the information:
    echo "<li><a href=\"javascript:create_window('$image_name',$image_size[0],$image_size[1])\">$image</a></li>\n";
     
    } // End of the IF.
        
    } // End of the foreach loop.
    ?>
     
    The problem is, when I click on any of the image links in Script 11.4, it shows a "Error 404 - File Not Found" message instead of the picture itself.  It also says something about the directory being "wrong or outdated".  I have not been able to fix this error, regardless of what I do.
     
    Could you give me any pointers as to what might be wrong?  Thanks!
     
     
×
×
  • Create New...