Steppio Posted April 22, 2008 Share Posted April 22, 2008 I'm having a few problems uploading jpegs and moving them into a new folder. I've looked all over the web for help and scanned the code a hundred times, so i think its time to ask for some help: if ($_FILES['usefile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['usefile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } if ($_FILES['userfile']['type'] != 'image/jpeg') { echo 'Problem: File is not a picture'; exit; } $currentdir=getcwd(); $target_path = $currentdir . "\\upload\\images\\" . basename($_FILES['userfile']['name']); echo "Target: $target_path<br>"; $temploc=$_FILES['userfile']['tmp_name']; echo "Temploc: $temploc<br>"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['userfile']['name']). " has been uploaded<br><br>"; } else { echo "There was an error uploading the file, please try again!<br><br>"; } The error i am receiving upon trying to move this file is: Target: C:\Program Files\Apache Group\Apache\htdocs\trans\upload\images\Windscreen.jpg Temploc: C:\WINDOWS\Temp\php137.tmp Warning: move_uploaded_file(C:\Program Files\Apache Group\Apache\htdocs\trans\upload\images\Windscreen.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache\htdocs\trans\add_product.php on line 77 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php137.tmp' to 'C:\Program Files\Apache Group\Apache\htdocs\trans\upload\images\Windscreen.jpg' in C:\Program Files\Apache Group\Apache\htdocs\trans\add_product.php on line 77 There was an error uploading the file, please try again! I really am at my wits end, any help would be greatly appreciated. Thanks in advance for your time. Steppio Quote Link to comment Share on other sites More sharing options...
zenag Posted April 22, 2008 Share Posted April 22, 2008 check .... $_FILES['usefile']['error'] ...in some lines u have assigned $_FILES['userfile'] Quote Link to comment Share on other sites More sharing options...
Steppio Posted April 22, 2008 Author Share Posted April 22, 2008 Yeah sorry overlooked that one, the Input field name is userfile, not usefile. Quote Link to comment Share on other sites More sharing options...
zenag Posted April 22, 2008 Share Posted April 22, 2008 if($_POST["submit"]=='submit'){ if ($_FILES["file"]["type"] == "image/jpeg") { if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } } //if ($_FILES['userfile']['type'] = 'image/jpeg') // { // echo 'Problem: File is not a picture'; // exit; // } $currentdir=getcwd(); $target_path = $currentdir . "\\upload\\images\\" . basename($_FILES['userfile']['name']); echo "Target: $target_path<br>"; $temploc=$_FILES['userfile']['tmp_name']; echo "Temploc: $temploc<br>"; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['userfile']['name']). " has been uploaded<br><br>"; } else { echo "There was an error uploading the file, please try again!<br><br>"; } } ?> <html><body> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="userfile" id="userfile" /> <input type="submit" name="submit" value="submit" /> </form></body></html> Quote Link to comment Share on other sites More sharing options...
Steppio Posted April 22, 2008 Author Share Posted April 22, 2008 Thanks for the suggestion but i've corrected the necessary names and am still having a great deal of trouble. Any help would be greatly appreciated. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Steppio Posted April 22, 2008 Author Share Posted April 22, 2008 Is the MIME type i am using correct to upload jpegs? Quote Link to comment Share on other sites More sharing options...
Steppio Posted April 22, 2008 Author Share Posted April 22, 2008 Is it even possible to do it this way? I'd usually use a blob type in database but the site soon runs slow and takes forever to flush the database. ANY suggestions? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 It looks like the path just doesn't exist. Do you have a folder named: C:\Program Files\Apache Group\Apache\htdocs\trans\upload\images\ ? Quote Link to comment Share on other sites More sharing options...
Steppio Posted April 23, 2008 Author Share Posted April 23, 2008 Darkwater ... i love you. I want to somehow produce offspring from you. They can share my total lack of perception and your lovely cranium. I literally cannot believe it all came down to that, 1 missing 's' (the folder name was //uploads//). I don't know how to thank you, i must have looked over that page (it's based on about 4 different form PHP_SELF reloads) a hundred times and never saw that. Your a star mate, got me out a diddley of a pickle there. Again - THANK YOU!!! 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.