Search code examples
phpfile-uploadpermissionstemp

Change where php downloads files to


I'm trying to make an upload module on my website, but I'm getting the following error:

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


Solution

  • uploading files is a dangerous thing. that's why there are restrictions in php to contain the danger. one of those restrictions is the "open_basedir" directive: it limits where php may read files (e.g. to include or require) and write files (e.g. to upload).

    It's a good idea to save the uploaded files in a place that is outside of the normal webspace, but then you have to add the upload directory to open_basedir, like so:

    See the manual at

    http://www.php.net/manual/en/ini.core.php#ini.open-basedir

    if you get this right, there are still about 100 things that might go wrong when uploading files, things that open up a vulnerability in your app. Read a lot about security + php before you attempt to do this!