supanoob Posted September 15, 2010 Share Posted September 15, 2010 When i use the following script to upload and resize an image, it throws out errors (see after script) <?php $image = $_FILES['image']['name']; $uploaddir = "./images/$gender/"; $pext = getExtension($image); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif")) { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only an image with the extension .jpg or .jpeg or .gif ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } $imgsize = GetImageSize($image); /*== check size 0=width, 1=height ==*/ if (($imgsize[0] > 460) || ($imgsize[1] > 345)) { $tmpimg = tempnam("/tmp", "MKUP"); system("djpeg $image >$tmpimg"); system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); unlink($tmpimg); } $rand = rand(0,9999999); $date = DATE("d.m.y"); $image_name=$date.$id.$rand.'.'.$extension; $final_filename = str_replace(" ", "_", $image_name); $newfile = $uploaddir . "/$final_filename"; if (is_uploaded_file($image)) { if (!copy($imgfile,"$newfile")) { print "Error Uploading File."; exit(); } } unlink($image); print("<img src=\"$newfile\">"); ?> errors: Warning: getimagesize(®Photo-0027.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/bumwarsc/public_html/images.php on line 77 Warning: unlink(®Photo-0027.jpg) [function.unlink]: No such file or directory in /home/bumwarsc/public_html/images.php on line 126 Quote Link to comment Share on other sites More sharing options...
love_bug Posted September 15, 2010 Share Posted September 15, 2010 try modifying folder path to "./images/$gender"; ? Quote Link to comment Share on other sites More sharing options...
supanoob Posted September 15, 2010 Author Share Posted September 15, 2010 try modifying folder path to "./images/$gender"; ? Thats the right path though :/ I have a working script, i just wanted to modify it to allow for image resizing. Quote Link to comment Share on other sites More sharing options...
love_bug Posted September 15, 2010 Share Posted September 15, 2010 i meant .. removing the Slash ( / ) at the end.. if you are receiving "No such file or directory" error.. that only comes up when path is wrong. I faced same problem while ago, removing slash at the end worked great for me Quote Link to comment Share on other sites More sharing options...
supanoob Posted September 15, 2010 Author Share Posted September 15, 2010 i meant .. removing the Slash ( / ) at the end.. if you are receiving "No such file or directory" error.. that only comes up when path is wrong. I faced same problem while ago, removing slash at the end worked great for me That didnt work, the pictures are uploading, it appears to be the temp and resizing that doesnt work :/ Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 15, 2010 Share Posted September 15, 2010 Hi there, <?php $image = $_FILES['image']['name']; $ext = strtolower($_FILES['image']['type']); $uploaddir = "./images/$gender/"; if (($ext != "image/jpg") || ($ext != "image/jpeg") || ($ext != "image/gif")){ This makes your script a little more secure, as this will help against people masking exe or the like when uploading, as this is the *actual file type* and not just the one after the full stop... Also, copy() and rename() technically do the same thing: See this And your filetype evaluator needs to be logical or not and, because what you are evaluating is not amounting to the sum of all conditions... Rw Quote Link to comment 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.