theredking Posted June 13, 2008 Share Posted June 13, 2008 I've been struggling with this for a couple of days now, and have done everything I can to try and solve the problem on my own, but I don't think I can. I have created a form to upload an image and sometimes it works, and sometimes it doesn't, and that's the problem! I want to be able to upload an image of max size 6M. I have tried this using PHP 5.2.6, and 4.4.8, and for both I have upload_max_filesize set to 6M, post_max_size set to 8M. With 4.4.8 it seems I can upload files up to 3MB, but if I try a 5.3MB file it fails, although I'm not totally convinced this is consistent yet, or why it fails. The problem is, I am also creating a thumbnail of this image and when using 4.4.8, I pretty consistently get an error saying "Allowed memory size of 33554432 bytes exhausted..." which is why I've been experimenting with 5.2.6. But, 5.2.6 rarely lets me upload an image larger than 1MB even though the settings (as stated above) are the same. So I am guessing that my problems with 4.4.8 are that there is not enough memory to perform the image resize using imagecreatefromjpeg function (as it successfully uploads the initial image but errors at the imagecreatefromjpeg script stage), and the problem with 5.2.6 is something to do with move_uploaded_file (as the error message occurs before the thumbnail script is attempted). I'm a novice when it comes to PHP, having just read Larry Ulman's PHP for the World Wide Web, but I'm trying my best! Any suggestions you may have will be greatly appreciated. Here is the code, currently I have the thumbnail code commented out as I was trying to trouble shoot the issues with move_uploaded_file in 5.2.6 function processForm() { $allowed_filetypes = array('.jpg','.JPG','.gif','.bmp','.png'); $max_filesize = 6291456; $upload_path = '/home/myserver/www/uploads/'; $upload_thumb_path = $upload_path.'thumbs/'; $filename = $_FILES['userfile']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); $filename = "{$_POST['last_name']}"."_"."{$_POST['first_name']}"."_".time() . "$ext"; if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) { print '<p>Your file has been successully uploaded, <a href="/uploads/' . $filename . '">click here</a> to view your file.</p>'; // It worked. /* if(copy($upload_path.$filename, $upload_thumb_path.$filename)) { print '<p>Thumbnail file created successfully. '; list($width, $height) = getimagesize($upload_path.$filename); $width_thumb = 160; $height_thumb = 200; $thumb = imagecreatetruecolor($width_thumb, $height_thumb); $source = imagecreatefromjpeg($upload_thumb_path.$filename); if(imagecopyresampled($thumb, $source, 0, 0, 0, 0, $width_thumb, $height_thumb, $width, $height)) { imagejpeg($thumb, $upload_thumb_path.$filename, 100); print 'Thumbnail successfully resized, <a href="/uploads/thumbs/' . $filename . '">click here</a> to view your file.</p>'; } else { print '<p>Thumbnail resize process hit a wall!</p>'; } } else { print '<p>Thumbnail hit a wall!</p>'; } */ } else print '<p>There was an error during the file upload. Please try again.</p>'; // End processForm function } Link to comment https://forums.phpfreaks.com/topic/109998-problems-with-move_uploaded_file/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.