Jump to content

problems with uploading because chmod isn't set correctly


bruckerrlb

Recommended Posts

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);
  
?>

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."; }

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.