PHP:move_uploaded_file()以未能打开流:没有这样的文件或目录
我试图让PHP从tmp目录移至一个上传的文件在我的网络服务器某处永久性的。它看起来很简单,但我得到这个错误:
I'm trying to get PHP to move an uploaded file from the tmp directory to somewhere permanent on my webserver. It seems simple enough, but I'm getting this error:
无法移动C:\\ UNISERVER \\ tmp目录\\ php3F62.tmp'到'静态/图像/幻灯片/ 1 / 1.JPG
pretty直接的,对不对?它无法找到目标文件夹。
Pretty straight-forward, right? It can't find the destination folder.
我的问题是:如何引用所需的目标目录
时的参考相对脚本的服务器上持何立场?或者是相对于网址是什么?或 PHP DOCUMENT_ROOT
?或操作系统的文件系统?还是其他什么东西?
Is the reference relative to the script's position on the server? Or is it relative to the URL? Or the PHP DOCUMENT_ROOT
? Or the OS's filesystem? Or something else?
我无法找到PHP文件中或者实际上在任何类似的问题在这里所以答案..
I can't find the answer in the PHP documentation or indeed in any of the similar questions here on SO..
谁能帮助?谢谢你。
一个简单的方法,以保持道路的轨迹就是在你的index.php来定义的绝对路径
A simple way to keep track of the path is just to define the absolute path in your index.php
define ('SITE_ROOT', realpath(dirname(__FILE__)));
然后,只需用它喜欢的:
Then just use it like:
move_uploaded_file($_FILES['file']['tmp_name'], SITE_ROOT.'/static/images/slides/1/1.jpg');