Iceman512 Posted March 21, 2007 Share Posted March 21, 2007 Hello all, I have written a php script for image handling which uploads an image and saves it in three states: the original image, a thumbnail and a watermarked 'preview' image. The script works perfectly every time, exactly as intended. However, if the image resolution exceeds 3.5 Megapixels in size, or about 1875 pixels in both directions (ie. Height and Width), the script either fails with 'The directory does not exist' or simply produces a blank white page. The physical size of the file doesn't affect the script at all - I use the ini_set("upload_max_filesize", "64M"); trick. For Example: 3.7MB image 1600 X 2150 - Succeeds 417Kb image 3008 X 2100 - Fails The site is hosted on a shared web server, so I cannot directly edit the php.ini or the config files. Can anyone shed some light on this problem and what may be causing it? Thanks in advance, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/43656-image-upload-fails/ Share on other sites More sharing options...
Orio Posted March 21, 2007 Share Posted March 21, 2007 The directive is not called max_upload_size, it's called upload_max_filesize. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/43656-image-upload-fails/#findComment-211926 Share on other sites More sharing options...
Iceman512 Posted March 22, 2007 Author Share Posted March 22, 2007 Hello all, Does anyone have any insight into this problem? Thanks, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/43656-image-upload-fails/#findComment-212667 Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 After changing it to upload_max_filesize it still doesn't upload? Orio. Quote Link to comment https://forums.phpfreaks.com/topic/43656-image-upload-fails/#findComment-212729 Share on other sites More sharing options...
Iceman512 Posted March 22, 2007 Author Share Posted March 22, 2007 Hi Orio, No. At the time of writing my first post, I didn't have the script to hand - the actual directive in the script was always set correctly, I only mentioned it (incorrectly) here in order to rule it out and say that I'm not having an upload size problem, only one of the image's resolution. Thanks for setting me straight though... Have you got any other ideas? Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/43656-image-upload-fails/#findComment-212859 Share on other sites More sharing options...
cmgmyr Posted March 22, 2007 Share Posted March 22, 2007 can you provide the script? Quote Link to comment https://forums.phpfreaks.com/topic/43656-image-upload-fails/#findComment-212874 Share on other sites More sharing options...
Iceman512 Posted March 23, 2007 Author Share Posted March 23, 2007 Hi Chris, Sure thing. Here it is: <?php if(isset($_POST['submit'])) { $size = 108; // the thumbnail height (default: 150) $filedir = '../downloads/'.$getfolder.'/'; // Original image dir $thumbdir = '../photos/'.$getfolder.'/'; // Thumbnail image dir $prefix = 'tn_'; // the prefix to be added to thumbnails $maxfile = '5120000'; // 5MB limit $mode = '0777'; // Default: 0666 $userfile_name = str_replace (' ', '_', $_FILES['image']['name']); $userfile_tmp = $_FILES['image']['tmp_name']; $userfile_size = $_FILES['image']['size']; $userfile_type = $_FILES['image']['type']; if (isset($_FILES['image']['name'])) { $prod_img = $filedir.$userfile_name; $prod_img_thumb = $thumbdir.$prefix.$userfile_name; move_uploaded_file($userfile_tmp, $prod_img); chmod ($prod_img, octdec($mode)); $sizes = getimagesize($prod_img); $aspect_ratio = $sizes[1]/$sizes[0]; if ($sizes[1] <= $size) { $new_width = $sizes[0]; $new_height = $sizes[1]; }else{ $new_height = $size; $new_width = abs($new_height/$aspect_ratio); } $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image'); $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); if(function_exists('imagecopyresampled')) { imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); }else{ Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing'); } ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving'); imagedestroy($destimg); } // WATERMARK THE IMAGE $markIt = '../photos/'.$getfolder.'/'; $mark_img = $markIt.$userfile_name; $image_location = $prod_img; $watermark_location = '../scripts/watermark.png'; $save_watermarked_file_to = $mark_img; require_once('scripts/watermark.php'); watermark($prod_img, $watermark_location, $save_watermarked_file_to); // TELL US THE PROGRESS/RESULT OF THE SCRIPT THUS FAR echo '<b>Image Preview:</b><br /><br />'; echo '<a href="'.$markIt.'" target="_blank"> <img src="'.$prod_img_thumb.'" width="'.$new_width.'" height="'.$new_height.'" style="border: 1px #EBEBEB;" /></a>'; // ADD DATABASE INPUT QUERY HERE $con = mysql_connect($dbhost,$dbuser,$dbpass); if (!$con) { die('<b>Error! </b>Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con); $put = "INSERT INTO $imgtable SET price = '$_POST[price]'"; if (!mysql_query($put,$con)) { exit('Error: ' . mysql_error()); } mysql_close($con); echo '<p style="padding:5px; background-color:#ffffcc; border: 1px solid #EBEBEB;">'; echo '<font color="#ff4500"><b>Action:</b></font><br />'; echo '<font color="#000000">'; echo 'Image successfully added to the database.'; echo '</font></p><p><br /></p>'; // END OF DATABASE QUERIES, SCRIPT FINISHED } ?> The configuration file for the database connection is loaded into the page as an include. I also haven't inlcuded the miscellaneous code responsible for the page formatting. Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/43656-image-upload-fails/#findComment-213366 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.