Tuesday, July 24, 2018

php - open_basedir restriction in effect in Plesk for Windows

I'm developing a CMS in PHP as a learning exercise but have hit a brickwall called "open_basedir restriction" - I am trying to upload a small JPG file. I've tried to give as much info as concisely as possible but let me know if I forgot anything!



I can see it hit the c:/windows/temp/ folder every time so its only falling over when trying to perform the move_uploaded_file operation.



After much research I know what this is and in theory how to fix it having read a number of pages online such as:



http://forum.parallels.com/showthread.php?258036-Plesk-Windows-open_basedir-restriction-in-effect




My Code



$uiq = uniqid();
$image_folder = "/img/articles/original/";
$uploaded = false;

if(isset($_POST['upload_image'])){
if($_FILES['userImage']['error'] == 0 ){
$up = move_uploaded_file($_FILES['userImage']['tmp_name'], $image_folder.$_FILES['userImage']['name']);
if($up){

$uploaded = true;
}
}
}


My PHPINFO



My PhpInfo results show that the root of my web hosting space is in the list of allowed folders:




open_basedir: F:\PLESK\WWW\mydomain.com\httpdocs\



The Error



PHP Warning: move_uploaded_file(): open_basedir restriction in effect. File(/img/articles/original/test.jpg) is not within the allowed path(s): (F:\PLESK\WWW\mydomain.com\httpdocs) in F:\PLESK\WWW\mydomain.com\httpdocs\sparklyphp\cms\modules\articles\edit\photos\index.php on line 40



More Errors



If I change my path




$image_folder = "/img/articles/original/";


to



$image_folder = "img/articles/original/";


I get additional errors:




PHP Warning:  move_uploaded_file(): open_basedir restriction in effect. File(C:\Windows\Temp\php393F.tmp) is not within the allowed path(s): (F:\PLESK\WWW\mydomain.com\httpdocs\) in F:\PLESK\WWW\mydomain.com\httpdocs\sparklyphp\cms\modules\articles\edit\photos\index.php on line 40
PHP Warning: move_uploaded_file(): open_basedir restriction in effect. File(C:\Windows\Temp\php393F.tmp) is not within the allowed path(s): (F:\PLESK\WWW\mydomain.com\httpdocs\) in F:\PLESK\WWW\mydomain.com\httpdocs\sparklyphp\cms\modules\articles\edit\photos\index.php on line 40
PHP Warning: move_uploaded_file(C:\Windows\Temp\php393F.tmp): failed to open stream: Operation not permitted in F:\PLESK\WWW\mydomain.com\httpdocs\sparklyphp\cms\modules\articles\edit\photos\index.php on line 40
PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php393F.tmp' to 'img/articles/original/test.jpg' in F:\PLESK\WWW\mydomain.com\httpdocs\sparklyphp\cms\modules\articles\edit\photos\index.php on line 40


** Hosting Environment **
The website hosting environment a Windows 2008 R2 box with Plesk 11.5 (the latest version/update) running PHP 5.4.16 in FastCGI mode. I have full admin access to the entire server.



The most frustrating thing here is that the file is being uploaded to the temp folder, I just can't get it from there!




Any help would be much appreciated!



Bob

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...