bruckerrlb Posted December 21, 2009 Share Posted December 21, 2009 I'm trying to upload a file, but I can't seem to get it to upload, I don't know how I can chmod it correctly to allow uploads. I'm using a local mamp server, can someone tell me what I'm doing wrong? <?php $thisdir = getcwd(); $company = $_POST['company']; mkdir($thisdir ."/$company" , 0777); $upload_path = '$company/'; $filename = $_FILES['userfile']['name']; $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); if(!is_writable($upload_path)) { die('You cannot upload to the specified directory, please CHMOD it to 777.'); } if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) { echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. } else { echo 'There was an error during the file upload. Please try again.'; } chmod($upload_path, 0777); ?> Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/ Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 I need to know what part is failing. Is it failing to create the folder or is it failing to upload the file? You need to determine which part is failing. Put an IF on the mkdir if (!mkdir("blah")) { echo "Failed to make directory."; } Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981779 Share on other sites More sharing options...
bruckerrlb Posted December 21, 2009 Author Share Posted December 21, 2009 It's making the folder fine, I can see it after the script is run, but there's just not anything inside. So, it's just not uploading Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981780 Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 Can you check the permissions on the folder? Is it set to 0777? Are you receiving an error? Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981782 Share on other sites More sharing options...
bruckerrlb Posted December 21, 2009 Author Share Posted December 21, 2009 The file permissions aren't set to 0777 because I can read and write but everyone else can only read. From how I understand how this works, I create a directory $thisdir = getcwd(); //get the path of my folder $company = $_POST['company']; // this is a variable from the form, user types in company name, and I create a path to go there mkdir($thisdir ."/$company" , 0777); // make the folder and give it these permissions but it's not setting at 0777 Then what happens is: $upload_path = '$company/'; // The place the files will be uploaded to $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. Then it's failing in the actual execution if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // I'd like for it to work, but it's not hitting here else echo 'There was an error during the file upload. Please try again.'; // This is where I'm getting the error So it's just not uploading, it's creating the path, but file permissions aren't getting set to 0777 because my folder says I can read and write but everyone else can only read. Thanks again Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981804 Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 $upload_path = '$company/'; // The place the files will be uploaded to '$company' is invalid. That string computes as $company Use "$company" I normally do "{$company}" as well just cause I like to make it pretty. Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981809 Share on other sites More sharing options...
bruckerrlb Posted December 21, 2009 Author Share Posted December 21, 2009 The thing is it's making a directory with the $company variable, so if I type in something like bruck in the form, I have a folder in my directory called bruck, but bruck doesn't have anything in it Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981812 Share on other sites More sharing options...
teynon Posted December 21, 2009 Share Posted December 21, 2009 Thats because the first time you reference it: mkdir($thisdir ."/$company" , 0777); You are using double quotes. However, when you are using it the second time, you are using single quotes. $upload_path = '$company/'; // The place the files will be uploaded to Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981814 Share on other sites More sharing options...
bruckerrlb Posted December 21, 2009 Author Share Posted December 21, 2009 Perfect, that was it, it's good to go now, thanks! Link to comment https://forums.phpfreaks.com/topic/185921-problems-with-uploading-because-chmod-isnt-set-correctly/#findComment-981820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.