Friday 5 January 2018

php - open_basedir restriction in effect

itemprop="text">

I have been having trouble using a
file upload script on my server - came to the conclusion that this was because PHP was
being run on Apache Module so reconfigured PHP to run as
FastCGI.




Unfortunately now when I try
to upload a file via uploadify I get the
error




Warning:
move_uploaded_file()[function.move-uploaded-file] open_base_dir restrictions in effect.
File(/var/www/vhosts/domain.com/uploads/filename.txt) is not within the allowed
path(s):(/var/www/vhosts/domain.com/httpdocs:/tmp) in
.....




It then
refers me to line 32 of my script which
reads:



move_uploaded_file($tempFile,$targetFile);



$tempFile
is as follows:



$tempFile =
str_replace("
","",$_FILES['Filedata']['tmp_name']);


I
have tried altering my vhost.conf file in numerous ways bit without success - it
currently stands as



            /var/www/vhosts/domain.com/httpdocs>

sapi_apache2.c>
php_admin_flag engine off
php_admin_flag
safe_mode on
php_admin_value open_basedir none
mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode
off
php_admin_value open_basedir none






I
seem to be going round in circles - it seems that the tmp directory is not being
found



Answer




If it's your server and you can actually mess
around with configuration, you can turn off the open_basedir in
your php.ini, reload PHP and try if it works. safe_mode should
be turned off in PHP by default as this option causes only
problems.



Or you can try
following:



            /var/www/vhosts/domain.com/httpdocs>
php_admin_value open_basedir
"/var/www/vhosts/domain.com/httpdocs/:/tmp/:/var/www/vhosts/domain.com/uploads/"




Same
can apply for the php.ini if you decide to set the config there.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...