Page 1 of 1

open_basedir restriction error, IIS

Posted: Sat Oct 17, 2009 8:59 am
by AntG
Hi,

I have a problem with "open_basedir restriction in effect" errors on using move_uploaded_file. GD is installed and enabled, Safe mode is off and open_basedir is set to the web site's root (all confirmed in phpInfo). I am using php 5.2.8 under IIS and have given IIS_IUSRS full control permissions on the receiving folder (a sub-directory of the web site's root).

I have a properly validated full script but this is my cut-down test that displays the problem...

Code: Select all

[color=#000080]<html>
	<head><title>PHP image resize</title></head>
	<body>
<?php
if (!isset($_POST['submitted'])) 
	{ 
?>
		<form method='post' action='test.php' enctype='multipart/form-data'>
			<input name='submitted'		type='hidden' value='TRUE' />
			File: <input name='imagefile'	type='file' />
			<input name='submit'		type='submit' value='Submit' />
		</form>
<?php
	} 
else $moved = move_uploaded_file($_FILES['imagefile']['tmp_name'], $_SERVER['DOCUMENT_ROOT']."\\images\\".$_FILES['imagefile']['name']);
?>
	</body>
</html>[/color]


Submitting a valid file using this page generates the following errors;

PHP Warning:  move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: 
		open_basedir restriction in effect. File(C:\Windows\Temp\phpF6F4.tmp) is not within the allowed path(s): 
		(C:\inetpub\wwwroot\default) in C:\inetpub\wwwroot\default\test.php on line 15

PHP Warning:  move_uploaded_file(C:\inetpub\wwwroot\default\images\108_6079.JPG) 
		[<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: 
		failed to open stream: Permission denied in C:\inetpub\wwwroot\default\test.php on line 15

PHP Warning:  move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: 
		Unable to move 'C:\Windows\Temp\phpF6F4.tmp' to 'C:\inetpub\wwwroot\default\images\108_6079.JPG' 
		in C:\inetpub\wwwroot\default\test.php on line 15

I have run out of ideas (though my inclination is to think the problem is in the IIS or Windows security area) - any suggestions?

 :banghead: Please!!

P.S. I know what I'm doing IT-wise but am relatively new to PHP.

Re: open_basedir restriction error, IIS

Posted: Sat Oct 17, 2009 1:06 pm
by requinix
Open up php.ini and add C:\Windows\Temp to the list of allowed paths. (Then restart IIS.)

Re: open_basedir restriction error, IIS

Posted: Sun Oct 18, 2009 7:00 am
by AntG
tasairis wrote:Open up php.ini and add C:\Windows\Temp to the list of allowed paths. (Then restart IIS.)
Unfortunately the open_basedir value is set in the applicationHost.config file where I can't add multiple paths... but I thought the whole point of move_uploaded_files was that the temporary upload folder didn't have to be within the allowed folder tree. If this is the solution then it would appear that the routine is not working correctly.

BTW - I'm running IIS7 under Vista Ultimate.

Moving the upload_tmp_dir and session.save_path from "C:\Windows\Temp" to "C:\inetpub\wwwroot\default\images" changes the errors to the following (note the continued reference to C:\Windows\TEMP\ even though I checked the change had taken effect using phpInfo);

PHP Warning: Unknown: open_basedir restriction in effect. File(C:\Windows\TEMP\) is not within the allowed path(s): (C:\inetpub\wwwroot\default) in Unknown on line 0
PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0

More and more confused.

Re: open_basedir restriction error, IIS

Posted: Sun Oct 18, 2009 10:02 am
by AntG
AntG wrote:note the continued reference to C:\Windows\TEMP\
Yes, well that's what led me to the solution, at last!

The answer is to give WRITE access on C:\Windows\Temp (or other folder pointed to by the TEMP environment variable) and to any receiving folder to the IUSR user.

Thanks for your help tasairis.