SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem uploading images

    --------------------------------------------------------------------------------

    Hi,

    Referring to the article "Php gallery system in minutes",
    I seem to be able to upload images fine if there are of a certain size ie. photos of a 872x1536 pixels are OK but other photos I've tried of 640x421 or 2048x1536 dimension do not upload correctly. One photo and its thumbnail seems to upload fine but when I try 2 or more the second thumbnail is not created but both images are uploaded OK. Then when I try more than 2 photos upload.php gives a blank page. Is this a known problem with the GD library, not being able to resize certain image dimensions?

    Any ideas??

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You may want to check both your apache and php configurations for limits on maximum upload size and maximum input size (upload_max_filesize, memory_limit, post_max_size, etc).

  3. #3
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan, I don't think this is the problem as upload_max_filesize, memory_limit etc are all 30MB - basically I can upload up to 30MB video, audio files fine, although the blank screen I get does seem strange. I really don't understand why a thumbnail for one image is created OK but not for others - its as though its GD to blame but not really sure. Have checked with webhost they say its fine and up to date - version 2.0.28.
    I'll try checking the error codes to find out further

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kevster
    I'll try checking the error codes to find out further
    Good idea. /var/log/httpd/error_log as well.

  5. #5
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When checking the $_FILES['userfile']['error'] array, I get an "unknown file error" (the default) and no error shows up in error log file. But this occurs with other image uploads which work out fine if I don't check them with $_FILES['userfile']['error'] array. Basically, all images of 872x1536 pixels or 1632x1224 upload OK, & when I upload one image of 640x421 or 2048x1536 pixels its OK too. Its just when I try more than 1 image of these dimensions I get a blank screen.

    I need a way of altering the dimensions of photos so that they upload OK ie. make them all 872x1536 pixels before they upload. Is there a way of doing this? My webhost reckons I should change to Imagemagick instead. I could always just hope that site users have images in the right format I suppose, had no prblems so far with them uploading images but in long run I really need this sorted.

  6. #6
    SitePoint Wizard simplecode's Avatar
    Join Date
    Jun 2006
    Posts
    1,129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please post your code here.
    am not sure but if ur trying to reduce the small image to another small one then u might get that blank screen.

  7. #7
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code is almost identical to that in the article, here it is:




    // initialization
    $result_final = "";
    $counter = 0;

    // List of our known photo types
    $known_photo_types = array(
    'image/pjpeg' => 'jpg',
    'image/jpeg' => 'jpg',
    'image/gif' => 'gif',
    'image/bmp' => 'bmp',
    'image/x-png' => 'png'
    );

    // GD Function List
    $gd_function_suffix = array(
    'image/pjpeg' => 'JPEG',
    'image/jpeg' => 'JPEG',
    'image/gif' => 'GIF',
    'image/bmp' => 'WBMP',
    'image/x-png' => 'PNG'
    );



    // Fetch the photo array sent by preupload.php
    $photos_uploaded = $_FILES['photo_filename'];

    // Fetch the photo caption array
    $photo_caption = $_POST['photo_caption'];

    //get max files size
    $file_size = $_FILES['photo_filename'] ['size'];
    $file_error= $_FILES['photo_filename'] ['error'];


    while( $counter <= count($photos_uploaded) )
    {





    if($photos_uploaded['size'][$counter] > 0)
    {







    mysql_query( "INSERT INTO photos(`photo_filename`,`photo_caption`) VALUES('0', '".strip_tags($photo_caption[$counter])."')" );
    $new_id = mysql_insert_id();
    $filetype = $photos_uploaded['type'][$counter];
    $extention = $known_photo_types[$filetype];


    $filename= "$new_id.$extention";


    mysql_query( "UPDATE photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

    // Store the orignal file
    move_uploaded_file($photos_uploaded['tmp_name'][$counter],$images_dir . '/' . $filename);


    // Let's get the Thumbnail size
    $size = GetImageSize( $images_dir."/".$filename );
    if($size[0] > $size[1])
    {
    $thumbnail_width = 100;
    $thumbnail_height = (int)(100 * $size[1] / $size[0]);
    }
    else
    {
    $thumbnail_width = (int)(100 * $size[0] / $size[1]);
    $thumbnail_height = 100;
    }

    // Build Thumbnail with GD 2.x.x

    $function_suffix = $gd_function_suffix[$filetype];
    $function_to_read = 'ImageCreateFrom' . $function_suffix;
    $function_to_write = 'Image' . $function_suffix;

    // Read the source file
    $source_handle = $function_to_read($images_dir . '/' . $filename);

    if ($source_handle) {
    // Let's create a blank image for the thumbnail
    $destination_handle =
    ImageCreateTrueColor($thumbnail_width, $thumbnail_height);

    // Now we resize it
    ImageCopyResampled($destination_handle, $source_handle,
    0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
    }

    // Let's save the thumbnail
    $function_to_write($destination_handle, $images_dir . '/tb_' . $filename);


    $result_final .= "<img src='".$images_dir. "/tb_".$filename."' />&nbsp;&nbsp;";
    }




    $counter++;
    }



    All error checking is done elsewhere and none appear so that is not the problem. The above script works completely fine with most image sizes and only produces a blank page when other sizes are uploaded. When this happens , no entry goes into the databse and no image file is moved to $images_dir. HOWEVER, when I upload just ONE different-sized image file it all seems to work fine, its just when I try multiple images that it goes wrong and I get the dreaded blank page.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •