2

I'm in the process of moving my sites from a shared hosting to a VPS (running CentOS with Plesk 10). When testing on my VPS I noticed that all of the sudden I couldn't upload files through a webform anymore.

I get a php error: Warning: move_uploaded_file(/uploads/logoklein.jpg): failed to open stream: No such file or directory in /var/www/vhosts/denkproducties.nl/httpdocs/denkproducties/upload.php on line 26 Warning: move_uploaded_file(): Unable to move '/tmp/php01nhmx' to '/uploads/logoklein.jpg' in /var/www/vhosts/denkproducties.nl/httpdocs/denkproducties/upload.php on line 26

There are tons of questions about this on SO, and they almost all involve setting the permissions right. I chmodded both the TMP and the uploads directory to 0777 (shudder), to no avail. I know 0777 isn't a smart thing to do, but I wanted to make sure it's not a permission issue for these folders.

Since the only thing that has changed is the VPS, I figured the problem must be on the server. I thought maybe the web server was running as 'nobody', so it couldn't access the tmp folder. I ran:

ps aux | grpe httpd

Which shows me:

root   27371   0.0  2.3   340860   24726  ?   SNs   12:57   0:00   /usr/sbin/httpd
apache 27372   0.0  0.9   240994    9820 ?    SN    12:57   0:00   /usr/sbin/httpd
apache 27373   0.0  1.6   341671   16700 ?    SN    12:57   0:00   /usr/sbin/httpd
apache 27374   0.0  1.6   341671   16700 ?    SN    12:57   0:00   /usr/sbin/httpd
apache 27375   0.0  1.6   341671   16700 ?    SN    12:57   0:00   /usr/sbin/httpd
apache 27376   0.0  1.6   341671   16700 ?    SN    12:57   0:00   /usr/sbin/httpd
apache 27377   0.0  1.6   341671   16700 ?    SN    12:57   0:00   /usr/sbin/httpd
apache 27378   0.0  1.6   341671   16700 ?    SN    12:57   0:00   /usr/sbin/httpd
root   27817   0.0  0.0   103244     824 tty1 S+    13:40   0:00   grep httpd

My server is running fCGI, by the way.

For completeness sake, I made a small upload script with a web form:

$allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
   $max_filesize = 1024000; // Maximum filesize in BYTES (currently 1MB).
   $upload_path = '/uploads/'; // The place the files will be uploaded to (currently a 'uploads' directory).


   $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.

   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');

   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');

   // Check if we can upload to the specified path, if not DIE and inform the user.
   //if(!is_writable($upload_path))
   //   die('You cannot upload to '. $upload_path .'the specified directory, please CHMOD it to 777.');

   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)){
         echo 'Your file upload was successful, view the file here'; // It worked.
     } else {
         echo 'There was an error during the file upload.  Please try again.'; // It failed :(.
 }

What am I missing here?

3 Answers 3

1

It looks like a permission or setting at fault which you clearly know already,

Check that /var/www/vhosts/denkproducties.nl/httpdocs/denkproductives/ does indeed.

Furthermore Apache looks like its running on the user account Apache so while doing a 777 a CHMOD on the folder you want writtable you might find that Apache got get into a parent folder due to the Exercute premission.

Change the ownership of /www/ to apache if its not already and furthermore when you do 777 ensure your using the -R attribute to make it recusive otherwise as I said a parent will be blocking it.

chmod -R 777 /var/www/

The above should do the trick.

If that doesn't work and this doesn't look like it would work but you could always try this in the upload file.

$upload_path = '$upload_path = '/denkproducties/uploads/';
1

take a small test as well to check if the directory exists with the following:

if( !file_exists($upload_path) ){
   exit('Directory not Found!');
}

the super global variable $_FILES also has the size of the file $_FILES['userfile']['size'] to check the following link to know more about the $_FILES

1
  • Thanks, but the directory exists. I know about the file size, but it isn''t uploading anything. May 31, 2013 at 10:01
0

Nothing problem just go to your file manager after login to your control panel. Then select the folder to which you want to move your file. And select it access option just right side of the folder icon than select particular user and allow read and right option by check the box.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.