Reputation: 53
I'm having a problem with move_uploaded_file
in PHP, with the returned error message telling me that the open_basedir restriction is in place (which I've set) and that on the path I'm attempting to write to is not within the allowed paths, but it is (and is clearly displayed on the error message).
Has anyone come across this before?
Edit:
Sorry, the error message might help!:
Unhandled Error (/var/www/vhosts/(myhost)/libs/imanager.php, 226): 2, '...move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/var/www/vhosts/(myhost)/httpdocs/tributes/images/precrop/1317227884228.jpg) is not within the allowed path(s): (/var/www/vhosts/(myhost)/httpdocs/tributes/images/precrop/:/tmp)...'
Upvotes: 4
Views: 1376
Reputation: 14554
Some directory in the path does not exist.
e.g.
; php.ini
open_base_dir = /var/www/a/b/c
if you move_uploaded_file('/var/www/a/b/c/d/1', $_FILES['x']['tmp_name'])
and you only have /var/www/a
but NOT /var/www/a/b
then you will get the misleading
open_basedir restriction in effect. File(/var/www/a/b/c/d/1) is not within the allowed path(s): (/var/www/a/b/c)'
which is weird.
After you create all the paths mentioned in open_base_dir, but still lack some inner directory, let's say you now have /var/www/a/b/c
but is lacking /var/www/a/b/c/d
, the same line as above will generate the error
move_uploaded_file(/var/www/a/b/c/d/1): Failed to open stream: No such file or directory in someScript.php:123
which makes much more sense.
So, the answer to your problem: you are missing directories that are part of the open_base_dir path.
Upvotes: 0
Reputation: 832
Note that open_basedir
will also fail if you have symlinks along the path. From http://php.net/open_basedir:
All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink.
Please check if /var/www/vhosts/(yourhost)/httpdocs/tributes/images/precrop/
is a real directory path, not symlinked one.
Upvotes: 0
Reputation: 382
There is PHP bug ("Regression (5.3.3-5.3.4) in open_basedir with a trailing forward slash"), that is triggered when open_basedir
have trailing slash. As workaround remove trailing slash from path in open_basedir
. This bug should be fixed in recent versions of PHP.
Upvotes: 0
Reputation: 10943
Not come across this before. You can only use move_uploaded_file if the file you are trying to move was uploaded using PHP. Try removing the trailing '/' from your precrop directory in the configuration.
There's some extra open_basedir information here: http://www.bigsoft.co.uk/blog/index.php/2007/12/30/fixing-php-s-require-open_basedir-restri
Upvotes: 0