views:

34

answers:

3

Hello,

My PHP script that uploads a file, cannot do so in directories at a higher level than itself.

For example: it will save in upload/ (a relative path at the same level as the script), but not in /usr/local/hello/ even though the file permissions are exactly the same. There are no issues with max upload size, max post size, execution time, and safe mode is off. Anyone have any thoughts? I can't even get an error message out-- just the $worked below returns false when it fails.

<?php
// Removed the rest of the error-checking code!
$contentDir = "/usr/local/hello/"; // <-- doesn't work, chmod 0777, owner: root, group root
//$contentDir = "upload/"; <-- works, chmod 0777 owner: root, group: root
error_reporting(E_ALL);
$filename = $_FILES["filey"]["name"];
$worked = move_uploaded_file(
              $_FILES["filey"]["tmp_name"], 
              $contentDir.$filename);
var_dump($worked);
?>

Edit: My open_basedir settings, given by phpinfo(), are:

Directive     Local Value   Master Value
open_basedir  no value  no value

Thanks!

+4  A: 

open_basedir configuration variable probably restricts the directories.

See open_basedir in the PHP manual.

Mewp
The value in phpinf() is `Directive Local Value Master Value``open_basedir no value no value`Is that not correct?
Jasie
If it has no value, it shouldn't restrict anything.
Mewp
+1  A: 

Please show us the content of $_FILES['filey']['error'], errors uploading files do not get reported as usual, but in that structure.

http://php.net/manual/en/features.file-upload.errors.php

Although it's very likely what Mewp said

Vinko Vrsalovic
Though I didn't add it in the question, the dump for this variable is always:`["error"]=> int(0)`: `Value: 0; There is no error, the file uploaded with success.`
Jasie
A: 

You're using the original client-side filename as the server-side filename. Does that filename already exist on the server? The directory might be 0777, but if that filename's there already, it also has to be writeable by the webserver's UID.

e.g. if you're uploading "resume.doc", does /usr/local/hello/resume.doc exist already? If it's not also mode 0777, then the move_uploaded_file() will fail.

The docs state that if the source file IS a valid uploaded file, but the move fails for any reason, a warning will be issued, so check your PHP error log for that.

Marc B