PhilipK Posted April 17, 2011 Share Posted April 17, 2011 Hello everyone I'm working on my first website with a image uploader. I am having problems setting the directory that includes 2 folders. My code is as follows $upload_location = "uploads/".$user."/".$fileName; $moveResult = move_uploaded_file($fileTmpLoc, $upload_location); It works when I change the code to ... $upload_location = "uploads/".$user."_".$fileName; $moveResult = move_uploaded_file($fileTmpLoc, $upload_location); How can I get it to work with a second folder? Link to comment https://forums.phpfreaks.com/topic/234001-problem-setting-directory/ Share on other sites More sharing options...
Pikachu2000 Posted April 17, 2011 Share Posted April 17, 2011 Does the directory already exist? Link to comment https://forums.phpfreaks.com/topic/234001-problem-setting-directory/#findComment-1202751 Share on other sites More sharing options...
PhilipK Posted April 17, 2011 Author Share Posted April 17, 2011 The directory may or may not exist. The script needs to be able to handle both situations. The uploads directory will always exist but the $user directory is based on the user_id Link to comment https://forums.phpfreaks.com/topic/234001-problem-setting-directory/#findComment-1202756 Share on other sites More sharing options...
dcro2 Posted April 17, 2011 Share Posted April 17, 2011 if(!file_exists("uploads/".$user."/")) { if(!mkdir("uploads/".$user)) echo "Failed creating user directory"; } $upload_location = "uploads/".$user."/".$fileName; $moveResult = move_uploaded_file($fileTmpLoc, $upload_location); Link to comment https://forums.phpfreaks.com/topic/234001-problem-setting-directory/#findComment-1202758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.