kwanjang Posted December 24, 2009 Share Posted December 24, 2009 I am getting this error when assigning a target file directory in the attached code.....The file upload works if I do not assign a upload location. "Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpjrO2Do' to 'http://www.nkmaa.ca/nkmaa/ldtuploads/freebl3.chk' in /home/nkma4081/public_html/nkmaa/uploads/upload.php on line 71 There was an error uploading the file, please try again! " //Windows way $uploadLocation = "http://www.nkmaa.ca/nkmaa/ldtuploads/"; //Unix, Linux way //$uploadLocation = "\uploads"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <div id="apDiv1"><a href="../members.html"><strong>Click Here to return to LDT Page</strong></a></div> <html> <head> <title>MicroPing domain status checker</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div id="caption">UPLOAD FILE</div> <div id="icon"> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data"> File to upload:<center> <table> <tr><td><input name="upfile" type="file" size="36"></td></tr> <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Upload"></td></tr> </table></center> </form> <?php if (isset($_POST['submitBtn'])){ ?> <div id="caption">RESULT</div> <div id="icon2"> </div> <div id="result"> <table width="100%"> <?php $target_path = $uploadLocation . basename( $_FILES['upfile']['name']); if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { echo "The file: ". basename( $_FILES['upfile']['name']). " has been uploaded!"; } else{ echo "There was an error uploading the file, please try again!"; } ?> </table> </div> Link to comment https://forums.phpfreaks.com/topic/186212-error-in-file-upload/ Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 To move a file you have to use the path on the server and not the web path. Meaning your path to move the file would look something like: $uploadLocation = $_SERVER['DOCUMENT_ROOT'] . "nkmaa/ldtuploads/"; That will give you something like: /home/nkma4081/public_html/nkmaa/ldtuploads/ Which is the correct server path and not the web path. Hope that makes sense. Link to comment https://forums.phpfreaks.com/topic/186212-error-in-file-upload/#findComment-983436 Share on other sites More sharing options...
kwanjang Posted December 24, 2009 Author Share Posted December 24, 2009 Thanks, I tried your suggestion and got the following error....The directory does exist though: "Warning: move_uploaded_file(/home/nkma4081/public_html../nkmaa/ldtuploads/LICENSE) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/nkma4081/public_html/nkmaa/uploads/ldtvideopage.php on line 66 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpsWAscU' to '/home/nkma4081/public_html../nkmaa/ldtuploads/LICENSE' in /home/nkma4081/public_html/nkmaa/uploads/ldtvideopage.php on line 66 There was an error uploading the file, please try again!" Here is the change I made: <?php $uploadLocation = $_SERVER['DOCUMENT_ROOT'] . "../nkmaa/ldtuploads/"; ?> <div id="apDiv1"><a href="../members.html"><strong>Click Here to return to LDT Page</strong></a></div> <div id="main"> <div id="caption">UPLOAD FILE</div> <div id="icon"> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data"> File to upload:<center> <table> <tr><td><input name="upfile" type="file" size="36"></td></tr> <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Upload"></td></tr> </table></center> </form> <?php if (isset($_POST['submitBtn'])){ ?> <div id="caption">RESULT</div> <div id="icon2"> </div> <div id="result"> <table width="100%"> <?php $target_path = $uploadLocation . basename( $_FILES['upfile']['name']); if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { echo "The file: ". basename( $_FILES['upfile']['name']). " has been uploaded!"; } else{ echo "There was an error uploading the file, please try again!"; } ?> </table> </div> <?php Link to comment https://forums.phpfreaks.com/topic/186212-error-in-file-upload/#findComment-983444 Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 You notice, you added the ../ I did not. Use this code in its entirety without changing it: $uploadLocation = $_SERVER['DOCUMENT_ROOT'] . "/nkmaa/ldtuploads/"; And it should work just fine. Link to comment https://forums.phpfreaks.com/topic/186212-error-in-file-upload/#findComment-983447 Share on other sites More sharing options...
kwanjang Posted December 24, 2009 Author Share Posted December 24, 2009 Awesome, works great.....Thank you very much. Have a merry Christmas. Link to comment https://forums.phpfreaks.com/topic/186212-error-in-file-upload/#findComment-983461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.