garydt Posted July 30, 2007 Share Posted July 30, 2007 Some users can upload photos while others can't. What would cause this? Upload form <form name="form1" id="Upload" action="<?php echo $editFormAction; ?>" enctype="multipart/form-data" method="POST"> <p> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"> </p> <h3> <input name="file" type="file" id="file" onchange="MM_showHideLayers('Layer1','','hide')" /> <span class="style1">for your photo</span> </h3> <p> <label> <input name="sent" type="hidden" id="sent" value="1" /> </label> </p> <h3 class="style7"> <input type="text" name="textfield" /> <span class="style2 style1">Add caption for the photo</span> </h3> <input name="submit" type="submit" id="submit" onclick="MM_showHideLayers('Layer1','','hide','Layer3','','show')" value="Upload your photo"> </p> <input type="hidden" name="MM_insert" value="form1"> </form> Script to upload, resize to 2 sizes and rename file. $editFormAction = ''; $max_file_size = 1024*1024*1024; //1MB if(isset($_POST['sent'])){ unset($submit); if (isset($_POST['sent'])) $submit = true; else die('Error: No file got sent'); if($_FILES['file']['name']) { $arr = getimagesize($_FILES['file']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['file']['tmp_name']); if($type == FALSE) { header("Location: uploadform2.php"); exit(); } elseif($type != 2) { header("Location: uploadform2.php"); exit(); } } $fieldname = $_FILES['file']; function resizeimage($name){ $filename = './uploads/'.$name; if(file_exists($filename)) { $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 100px; max width: 100px if($im_width >= $im_height) { $im_divice = $im_width / 140; }else { $im_divice = $im_height / 140; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "thumbnails/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } function resizelarger($name){ $filename = './uploads/'.$name; if(file_exists($filename)) { $image = imagecreatefromjpeg($filename); //unresized image $im_info = getimagesize($filename); //unresized image $im_width = $im_info[0]; $im_height = $im_info[1]; $im_flag = $im_info[2]; //max height: 100px; max width: 100px if($im_width >= $im_height) { $im_divice = $im_width / 300; }else { $im_divice = $im_height / 300; } $thumb_width = $im_width / $im_divice; $thumb_height = $im_height / $im_divice; //create empty image $thumb = imagecreatetruecolor($thumb_width, $thumb_height); //resize image imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height); if(imagejpeg($thumb, "smallpics/".$name, 80)) { //image-resource, filename, quality return 1; } imagedestroy($thumb); //destroy temporary image-resource imagedestroy($image); //destroy temporary image-resource } } // make a note of the directory that will recieve the uploaded file // full url $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploads/'; $uploadsDirectory = './uploads/'; //Upload image $uploadFilename = $uploadsDirectory.$fieldname['name']; // now let's move the file to its final location and allocate the new filename to it move_uploaded_file($fieldname['tmp_name'], $uploadFilename); $user = ($_SESSION['MM_Username']); $a = rand(0,9999); resizeimage($fieldname['name']); rename("thumbnails/".$fieldname['name'], "thumbnails/".$user.$a.$fieldname['name']); $smallimage = './thumbnails/'.$user.$a.$fieldname['name']; resizelarger($fieldname['name']); rename("smallpics/".$fieldname['name'], "smallpics/".$user.$a.$fieldname['name']); $smallpics = './smallpics/'.$user.$a.$fieldname['name']; unlink($uploadFilename); Why does it work for some users and not for others? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/ Share on other sites More sharing options...
tryingtolearn Posted July 30, 2007 Share Posted July 30, 2007 What does it do for the users that cant upload? It could be that the file is over the 1MB max file size or the file is not a .jpg??? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310792 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 yes its the max file size as i've just tried a file over 1mb and got an error. How do you increase max file size? Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310813 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 I've put $max_file_size = 4096*4096*4096; //4MB and i still get Error 500 internal server error. What can i do? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310824 Share on other sites More sharing options...
ViN86 Posted July 30, 2007 Share Posted July 30, 2007 there are a couple things that need to be done when changing the file upload size. all of them should be done through the php.ini settings file. file_uploads 1 # file uploads on upload_max_filesize 5M #here, enter the number followed by K (kilobyte), M (megabyte), G (gigabyte) post_max_size 5M # equal to or greater than max filesize max_execution_time 60 # in seconds, needs to be high enough to prevent timeouts, can also use set_time_limit(0) at top of php script max_input_time 60 #time values need to be set high enough for files to upload also, if you declare settings from your php script, use the ini_set() function gl Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310830 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks Do i then upload the php.ini file to the server's root directory or to another directory? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310833 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 I've uploaded the php.ini-recommended file upto the server and i still get error 500 when uploading files bigger than 1mb. shall i rename file to php.ini I'm finding out about ini_set as havent used it before. Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310845 Share on other sites More sharing options...
ViN86 Posted July 30, 2007 Share Posted July 30, 2007 the file must benamed php.ini thats the file PHP uses for settings. the php.ini-recommended is the recommended settings file. Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310854 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 I've put- ini_set("upload_max_filesize","8M"); ini_set("file_uploads","1"); ini_set("post_max_size","8M"); i still get internal server error. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310855 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks. i've renamed the php.ini file and now after trying to upload file i get a blank white screen Now what? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310862 Share on other sites More sharing options...
ViN86 Posted July 30, 2007 Share Posted July 30, 2007 php pages still load/work? ie, is the upload page itself, or the page that handles the files going white? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310870 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 Its the upload page itself that goes blank white after i clickd upload. It does upload the file as i see the browser working for 20 secs and then it goes blank white on the same page. What does that mean? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-310975 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-311079 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 I've put- <input type="hidden" name="MAX_FILE_SIZE" value="80000000"> I get error 500 internal server error when a file bigger than 1mb is uploaded. Why? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-311222 Share on other sites More sharing options...
garydt Posted July 30, 2007 Author Share Posted July 30, 2007 The server on which my website is host has a default max_filesize of 20mb so i can't understand why it won't accept files bigger than 1mb. Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-311224 Share on other sites More sharing options...
garydt Posted July 31, 2007 Author Share Posted July 31, 2007 I'm still having trouble. Can I have some more help please? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-311742 Share on other sites More sharing options...
ViN86 Posted July 31, 2007 Share Posted July 31, 2007 so php is still functioning (ie another php page on the server loads) but the upload page isnt working? Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-311822 Share on other sites More sharing options...
Iceman512 Posted July 31, 2007 Share Posted July 31, 2007 Hi there garydt, I have struggled with this exact same problem for ages. Unfortunately, no one could answer the 'white page' issue definitively. The server's php.ini file checks many variables that the image has to comply with before it will be transferred (uploaded) to it's final destination. I don't know why the white page occurs without displaying an error, but my theory is that the server runs out of memory. When you are uploading a JPEG file (or any other image format for that matter) the image is already compressed on your hard drive. The server must first uncompress the image to process the data contained within. To get an accurate measurment of how much memory is required, multiply the H x W of the image by 4 (4 bytes of data per pixel). The result will give you a relative size of the image uncompressed. Eg: 1200 x 800 image (1200 x 800 x 4= 3840000) - 3.84 MB Try setting the php_ini limit higher at the top of your script using ini_set. Try 64MB. Also, the server may have a limit of the actual pixel size that it will allow, for example, 1500 x 1500. Try uploading a small image, but with a large file size (eg. 800 x 600 at 3MB) then try uploading a large image with a small file size (eg. 2500 x 2500 at 250Kb) and see what you get. Obviously, there are tons more suggestions I could give you, but this is a process of elimination to eradicate what is not wrong. Give that a try and let us know how it goes. I hope it helps you out! Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/62451-upload-script-wont-always-work/#findComment-311963 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.