views:

528

answers:

2

Hi

I have been working on a upload file that works fine on localhost (windows) but wont work on my linux server I rent. I want it to move it to a subdir '/files' from where the file is.

it gives the errors: Warning: move_uploaded_file(/home/taalhulp/domains/taalhulpmanager.nl/public_html/files/6) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/taalhulp/domains/taalhulpmanager.nl/public_html/Gegev_Dossier.php on line 66

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFMaeAs' to '/home/taalhulp/domains/taalhulpmanager.nl/public_html/files/6' in /home/taalhulp/domains/taalhulpmanager.nl/public_html/Gegev_Dossier.php on line 66

Here is a simplified version of my code

$FotoMap = '/home/taalhulp/domains/taalhulpmanager.nl/public_html/files/' ;

if ($_POST['type'] == 'add' & strlen($_FILES['FileUpload']['name']) > 0 && strlen($_POST["GivenFileName"]) > 0 )
{
    if (move_uploaded_file($_FILES['FileUpload']['tmp_name'], $FotoMap . $file_name_id))
  {
       $_SESSION['echo'] = 'succes';

  }
  else
  {
       $_SESSION['echo'] = 'fail';
  }
}

it says permission denied but is that because I do something wrong or because i need to contact my provider to tell him to enable that, maybe you I can enable that myself?

A: 

you probably don't have permissions (PHP engine / apache webserver) to access the directory for temporary uploads. try to set your custom temp path.

dusoft
"try to set your custom temp path." how?
matthy
if you can edit php.ini, then do it. if not, try to change value via ini_set()
dusoft
**@dusoft:** I really don't think the `/tmp` directory is the problem here. The error message indicates that it wrote to `/tmp` without any problems. It's the directory he moves the files into that doesn't have `+w+x`.
Andrew Moore
+2  A: 

Make sure that /home/taalhulp/domains/taalhulpmanager.nl/public_html/files/'s permissions are set to 0777.

I do not recommend doing that as it opens a bunch of security issues. You would be better finding out on which user or group the script is being run and modify the directory to be owned by that user instead.

Andrew Moore
I think you'd be better off not mentioning the first suggestion at all. Your second point is preferred by far.
Dana the Sane
**@Dana the Sane:** The first point is there for thoroughness.
Andrew Moore
And the second point is sometimes out of reach for people with no understanding of how *nix permissions work or without the ability to change the owner of their files.
Andrew Moore