jponte Posted April 9, 2010 Share Posted April 9, 2010 Hi, I'm having issues uploading a file file to my server with a very small and simple script. It works when I do not create a new folder and leave everything in the Uploads folder but I would like to create an individual folder with the ticket number provided in the form and store all submited files there. <?php $ticket_number = $_POST['ticketnumber']; mkdir("uploads/$ticket_number", 0777); chmod("uploads/", 0777); chmod("uploads/$ticket_number", 0777); $mydir = "uploads/$ticket_number"; if(chmod(realpath($myDir), 0777)) { echo 'Successfully changed dir to 0777 permissions!'; } $target_path = "uploads"; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path .'/'. $ticket_number)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded<br>"; echo $ticket_number; } else{ echo "There was an error uploading the file, please try again!"; } clearstatcache(); echo 'Permissions: ' . substr(sprintf('%o', fileperms($mydir)), -4); // Result here is 0777 ?> The paths are all fine. Here are the errors I get: Warning: move_uploaded_file(uploads/ww) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Documents and Settings\jack.ponte\Desktop\Website\logs\uploader.php on line 56 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/tmp\php13E.tmp' to 'uploads/ww' in C:\Documents and Settings\jack.ponte\Desktop\Website\logs\uploader.php on line 56 Any help will be appreciated. Jack P Quote Link to comment https://forums.phpfreaks.com/topic/198057-problem-uploading-file/ Share on other sites More sharing options...
JAY6390 Posted April 9, 2010 Share Posted April 9, 2010 chmod won't work on a windows based system Quote Link to comment https://forums.phpfreaks.com/topic/198057-problem-uploading-file/#findComment-1039255 Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2010 Share Posted April 9, 2010 You are not specifying the file name portion of the destination in the move_uploaded_file() function. Quote Link to comment https://forums.phpfreaks.com/topic/198057-problem-uploading-file/#findComment-1039257 Share on other sites More sharing options...
phporcaffeine Posted April 9, 2010 Share Posted April 9, 2010 The mkdir construct will not recursively build a path, you must explicitly create each node. Incorrect: mkdir('parent/child'); Correct: mkdir('parent'); mkdir('parent/child'); Quote Link to comment https://forums.phpfreaks.com/topic/198057-problem-uploading-file/#findComment-1039262 Share on other sites More sharing options...
jponte Posted April 9, 2010 Author Share Posted April 9, 2010 Hi, Thanks PFMaBiSmAd. As you said, I did not have the file name to be write, So I added/changed the following 3 $target_path = "uploads/$ticket_number/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { Peace, JP Quote Link to comment https://forums.phpfreaks.com/topic/198057-problem-uploading-file/#findComment-1039295 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.