|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-07-11 07:25 UTC] tony2001@php.net
[2007-07-11 16:03 UTC] nlgordon at iastate dot edu
[2007-07-11 16:20 UTC] tony2001@php.net
[2007-07-11 16:36 UTC] nlgordon at iastate dot edu
[2007-07-11 16:47 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 16:00:01 2025 UTC |
Description: ------------ When uploading a file in a virtual host that has open_basedir enabled and upload_tmp_dir unset the upload fails. Documentation claims that move_uploaded_file is open_basedir aware, which might be all well and true, but the file upload it self is not open_basedir aware. It would also appear that upload_tmp_dir is not open_basedir aware. I believe I have isolated it down to line 230 of php_open_temporary_file.c in the php_open_temporary_fd function: <snippet lines="226-235"> if (!dir || *dir == '\0') { def_tmp: temp_dir = php_get_temporary_directory(); if (temp_dir && *temp_dir != '\0' && !php_check_open_basedir(temp_dir TSRMLS_CC)) { <--- Problem area return php_do_open_temporary_file(temp_dir, pfx, opened_path_p TSRMLS_CC); } else { return -1; } } </snippet> The php_open_temporary_fd function is referenced by the file upload handling code in rfc1867.c In short the open_basedir check is unnecessary in the case of file uploads since page code can not affect the temp directory uploaded to and move_uploaded_files works correctly. Reproduce code: --------------- <?php if ($_POST['submit']) { echo "<pre>"; print_r($_FILES); move_uploaded_file($_FILES['uploaded']['tmp_name'], '/afs/iastate.edu/virtual/itssilver/WWW/uploads/' . $_FILES['uploaded']['name']); // move_uploaded_file(); } ?> <form action="/testing/upload.php" enctype="multipart/form-data" name="form_1" method="post"> Upload <input name="uploaded" type="file" size="50"/> <input name="submit" type="submit" value="Submit"/> </form> Expected result: ---------------- $_FILES['uploaded'] should be filled with the information relating to a successful upload. Actual result: -------------- Apache error log: [Tue Jul 10 14:25:07 2007] [error] [client ***] PHP Warning: Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/afs/iastate.edu/virtual/itssilver/) in Unknown on line 0, referer: http://silver.its.iastate.edu/testing/upload.php [Tue Jul 10 14:25:07 2007] [error] [client ***] PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0, referer: http://silver.its.iastate.edu/testing/upload.php Also, this error is never sent to the browser, it would appear that the internal engine does not have enough information about the script being run to identify the file even being run in.