更改 php 下载文件的位置
我正在尝试在我的网站上制作上传模块,但出现以下错误:
PHP 警告:未知:open_basedir 限制生效。文件(C:\Windows\TEMP) 不在允许的路径内:(E:\Domains\medisearch.com.br) 在第 0 行未知 PHP 警告:文件上传错误 - 无法在第 0 行的未知中创建临时文件
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你不能在你的 php 脚本上执行此操作,但是如果你有权访问 php.ini 那么你可以更改 upload_tmp_dir
从那里。你不能在 php 中更改它,因为它是 PHP_INI_SYSTEM 指令
You cant do this on you php script, but if you have access to php.ini then you can change upload_tmp_dir
from there. You cannot change this in php because it is PHP_INI_SYSTEM directive
上传文件是一件危险的事情。这就是为什么 php 有限制来遏制危险。这些限制之一是“open_basedir”指令:它限制 php 可以读取文件(例如包含或要求)和写入文件(例如上传)的位置。
最好将上传的文件保存在正常网络空间之外的位置,但随后您必须将上传目录添加到 open_basedir,如下所示:
上的手册
请参阅http://www.php.net/manual/en/ini.core.php#ini.open- basedir
如果你得到这个是的,上传文件时仍然有大约 100 个可能出错的地方,这些地方会在您的应用程序中打开漏洞。在尝试执行此操作之前,请阅读大量有关安全性 + php 的内容!
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!
打开 php.ini 并搜索“upload_tmp_dir”
将其更改为新位置
Open up php.ini and search for "upload_tmp_dir"
Change this to the new location
有一个 php.ini 设置,
upload_tmp_dir
控制该目录。您必须在 php.ini 级别更改它。在脚本中通过
ini_set()
执行此操作将不起作用 - 上传早在脚本开始执行之前就已中止。There's a php.ini setting,
upload_tmp_dir
which controls that directory. You must change it at the php.ini level. Doing it viaini_set()
within your script will not work - the upload will have been aborted long before your script ever starts executing.