xgd Posted October 16, 2008 Share Posted October 16, 2008 Hi all. i am trying out this script with which i am suppoused to upload a text file to a destination directory, but am having trouble with the destination directory. I have made a directiry called "uploads" in my root folder, and the part of the code is : ..... // put the file where i want it $upfile = '/uploads/'.$_FILES['userfile']['name']; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo 'Problem: Could not move file to destination directory'; exit; } } else ...... But every time i try to upload the file it says the directory doesnt exist or smth like that. "failed to open stream". Everything else works, the problem is in the folder, but i cant figure out whats wrong. What do you guys think ? Help please. Quote Link to comment https://forums.phpfreaks.com/topic/128716-upload-directory-problem/ Share on other sites More sharing options...
GKWelding Posted October 16, 2008 Share Posted October 16, 2008 Check your chmod setting on the folder to make sure it's writable. Quote Link to comment https://forums.phpfreaks.com/topic/128716-upload-directory-problem/#findComment-667101 Share on other sites More sharing options...
xgd Posted October 16, 2008 Author Share Posted October 16, 2008 It is. this is what i get: Warning: move_uploaded_file(/uploads/New Text Document.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home2/xgdstudi/public_html/php/upload.php on line 34 any other ideas ? Quote Link to comment https://forums.phpfreaks.com/topic/128716-upload-directory-problem/#findComment-667125 Share on other sites More sharing options...
MadTechie Posted October 16, 2008 Share Posted October 16, 2008 Try $upfile = '../uploads/'.$_FILES['userfile']['name']; Quote Link to comment https://forums.phpfreaks.com/topic/128716-upload-directory-problem/#findComment-667130 Share on other sites More sharing options...
GKWelding Posted October 16, 2008 Share Posted October 16, 2008 Spotted it! You have spaces in the filename of your text document, it's looking for a folder called 'new' in your uploads dir. Replace the spaces with underscores. Quote Link to comment https://forums.phpfreaks.com/topic/128716-upload-directory-problem/#findComment-667131 Share on other sites More sharing options...
xgd Posted October 16, 2008 Author Share Posted October 16, 2008 Sorry for not using code]. I tried what you both said, it didnt work. I get this warning below the first one as well (i'm testing locally). Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:/Documents and Settings/voja/Desktop/EasyPHP 2.0b1\tmp\phpDF.tmp' to '../uploads/testfile.txt' in C:\Documents and Settings\voja\Desktop\EasyPHP 2.0b1\www\upload.php on line 34 Problem: Could not move file to destination directory Maybe you can find the problem from that ? Quote Link to comment https://forums.phpfreaks.com/topic/128716-upload-directory-problem/#findComment-667191 Share on other sites More sharing options...
MadTechie Posted October 16, 2008 Share Posted October 16, 2008 if the upload.php is on the root and the uploads folder is also on the root try $upfile = dirname(__FILE__).'/uploads/'.$_FILES['userfile']['name']; Quote Link to comment https://forums.phpfreaks.com/topic/128716-upload-directory-problem/#findComment-667552 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.