adam291086 Posted December 11, 2007 Share Posted December 11, 2007 I have an upload script sort of working. One file always uploads anything else wont. Can anyone tell me why <?php error_reporting(E_ALL); if ($_SERVER['REQUEST_METHOD'] == "POST") { $pext = getFileExtension($imgfile_name); $pext = strtolower($pext); if ($pext == 'jpg' || $pext == 'jpeg' || $pext == 'png' || $pext == 'PNG' || $pext == 'gif' || $pext == 'GIF'){ //big pic $smallpath= dirname(__FILE__)."/pictures/picture"; $smallfinal_filename = str_replace(" ", "_", $imgfile_name); $newfile = $smallpath ."/$smallfinal_filename"; if (is_uploaded_file($imgfile)) { if (!copy($imgfile,"$newfile")) { echo "Error Uploading File."; @unlink($imgfile); } } //small picture $path= dirname(__FILE__)."/pictures/thumbnail"; //-- RE-SIZING UPLOADED IMAGE $imgsize = GetImageSize($imgfile); if (($imgsize[0] > 100) || ($imgsize[1] > 100)) { $tmpimg = tempnam("/tmp", "MKUP"); system("djpeg $imgfile >$tmpimg"); system("pnmscale -xy 100 100 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); unlink($tmpimg); } $final_filename = str_replace(" ", "_", $imgfile_name); $newfile = $path ."/$final_filename"; if (is_uploaded_file($imgfile)) { if (!copy($imgfile,"$newfile")) { echo "Error Uploading File."; @unlink($imgfile); } else { echo "success"; } } } else { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } } ?> <html> </head> <body bgcolor="#FFFFFF"> <h2>Upload and Resize an Image</h2> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="50000"> <p>Upload Image: <input type="file" name="imgfile"><br> <font size="1">Click browse to upload a local file</font><br> <br> <input type="submit" value="Upload Image"> </form> </body> </html> <?php /*== FUNCTIONS ==*/ function getFileExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } ?> Quote Link to comment Share on other sites More sharing options...
Lumio Posted December 11, 2007 Share Posted December 11, 2007 Did you do some debuging? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 11, 2007 Author Share Posted December 11, 2007 yeah, i have echoed all the file names and they are present. It so werid. It uploads bluehills.jpg but anthing returns the form. Quote Link to comment Share on other sites More sharing options...
adam291086 Posted December 11, 2007 Author Share Posted December 11, 2007 after more debgging i am more confused. When i echo $imgfile i only get the result for bluehill.jpg. Anything else isn't set as a variable. Any ideas? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 12, 2007 Share Posted December 12, 2007 Your code has two basic problems. It is dependent on register globals being on and it is not checking the $_FILES['imgfile']['error'] element to even make sure that the upload worked before accessing the uploaded file information. Reading this will help - http://www.php.net/manual/en/features.file-upload.php 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.