trandrus Posted April 16, 2008 Share Posted April 16, 2008 Have code to upload a file to a dir and nothing happens. No errors, the file simply doesn't upload. The path is correct, the dir is chmod 777, the file is less than maxfilesize. no matter what i do it always says "file was not moved": <?php error_reporting(E_ALL); if ($HTTP_POST_VARS) { foreach ($HTTP_POST_VARS as $field) { if (!$field) { echo "empty"; } } } if ($_FILES) { $target_path = "/uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); echo $target_path; echo $_FILES['uploadedfile']['name']; if (move_uploaded_file($_FILES['uploadedfile']['name'], $target_path)) { echo "file was moved to ".$target_path; }else { echo "file was not moved"; } } ?> <form enctype="multipart/form-data" action="application.php" method="POST"> <table width="526" border="0" cellspacing="0" cellpadding="0"> <tr> <td bgcolor="#F5F5F5" class="textreg"><br> <span class="textbold"> Applicant Personal Information</span>: <br> <br> <table width="526" border="0" cellspacing="0" cellpadding="1"> <tr> <td width="197" align="right" class="textreg">First Name: </td> <td width="325" class="textreg"><input type="text" name="firstname" size="27" /></td> </tr> <tr> <td align="right" valign="top" class="textreg">Last Name: </td> <td class="textreg"><input type="text" name="lastname" size="27" /></td> </tr> <tr> <td align="right" valign="top" class="textreg">Address: </td> <td class="textreg"><input type="text" name="address" size="27" /></td> </tr> <tr> <td align="right" valign="top" class="textreg">City, State, Zip Code: </td> <td class="textreg"><input type="text" name="citystatezip" size="27" /></td> </tr> <tr> <td align="right" valign="top" class="textreg">Phone: </td> <td class="textreg"><input type="text" name="phone" size="27" /></td> </tr> <tr> <td align="right" valign="top" class="textreg">Position Title Description: </td> <td class="textreg"><select name="position" size="1" > <option>Select Position</option> <option>Senior Project Manager</option> <option>Assistant Field Engineer</option> </select></td> </tr> <tr> <td align="right" valign="top" class="textreg">Email: </td> <td class="textreg"><input type="text" name="email" size="27" /></td> </tr> <tr> <td align="right" valign="top" class="textreg">Comments: </td> <td class="textreg"><textarea name="comments" id="comments"></textarea></td> </tr> </table> <span class="textreg"><br> </span> <table width="526" border="0" cellspacing="0" cellpadding="1"> <tr> <td width="10"> </td> <td class="textreg">After completing all of the fields above, attach a copy of your resume. You can do this by selecting 'Choose' and locating the file on your computer. Select 'Send' when finished. Word and Acrobat PDF files are the preferred formats.<br> <br><center> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <input name="uploadedfile" type="file" value="Browse"/> <input type="submit" value="Send" /> </center> <br> </td> <td width="15"> </td> </tr> </table> <br> </td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/ Share on other sites More sharing options...
haku Posted April 16, 2008 Share Posted April 16, 2008 Where is your uploads file located? If it's in the same folder as the script that processes the form, then you need to drop that leading slash from "/uploads/". Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-518564 Share on other sites More sharing options...
trandrus Posted April 16, 2008 Author Share Posted April 16, 2008 its in the same folder however i modified it on the forum post to keep the client's name anon: /client/application.php (html with form) /client/uploads/ in my code it looks like this: $target_path = "/client/uploads/"; Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-518608 Share on other sites More sharing options...
haku Posted April 16, 2008 Share Posted April 16, 2008 Then it should be like this: $target_path = "uploads/"; Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-518614 Share on other sites More sharing options...
trandrus Posted April 16, 2008 Author Share Posted April 16, 2008 tried that and i get the same "file was not moved" [target_path] => uploads/test.gif Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-518623 Share on other sites More sharing options...
haku Posted April 16, 2008 Share Posted April 16, 2008 Then your problem is somewhere else. But you can't have that leading slash there. Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-518697 Share on other sites More sharing options...
haku Posted April 16, 2008 Share Posted April 16, 2008 I just found your problem (other than the leading slash). Its a little late here and I'm tired. if (move_uploaded_file($_FILES['uploadedfile']['name'], $target_path)) Should be if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-518704 Share on other sites More sharing options...
craygo Posted April 16, 2008 Share Posted April 16, 2008 you can't move the file name. it's just a name it doesn't exist. The file you move is the temp file php creates if (move_uploaded_file($_FILES['uploadedfile']['name'], $target_path)) { Should be if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { Ray EDIT: LOL there must be an echo in here Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-518707 Share on other sites More sharing options...
trandrus Posted April 17, 2008 Author Share Posted April 17, 2008 i see [tmp_name] => /tmp/php5It6UV thats the file thanks!!!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-519091 Share on other sites More sharing options...
shankar23 Posted April 17, 2008 Share Posted April 17, 2008 try this code friend it will make a difference.. <?php error_reporting(E_ALL); if ($HTTP_POST_VARS) { foreach ($HTTP_POST_VARS as $field) { if (!$field) { echo "empty"; } } } if ($_FILES) { $PATH = dirname(__file__); $target_path = "\uploads\\"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $fullPath = $PATH.$target_path; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$fullPath)) echo "file was moved to ".$target_path; else echo "file was not moved"; } ?> Link to comment https://forums.phpfreaks.com/topic/101390-file-upload-not-workingtried-everything-i-can-think-of/#findComment-519219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.