简体   繁体   English

move_uploaded_file不起作用

[英]move_uploaded_file not working

I'm uploading files via JS and storing the temp path in the session. 我正在通过JS上传文件,并将临时路径存储在会话中。 Than i use the following code to move the files. 比起我,我使用下面的代码来移动文件。

if(move_uploaded_file($_SESSION['temp_img'][$key]['path'], $dest.$bigimg)){

$dest and $bigimg are defined earlier in the script with the id from the database. $dest$bigimg是在脚本中使用数据库ID定义的。

Any Ideas or alternatives ? 有任何想法或选择吗?

MANCHUCK's answer was close but not quite there. 曼查克的答案很接近,但还远远不够。 You must call move_uploaded_file within the script where the file was uploaded. 您必须在上传文件的脚本内调用move_uploaded_file You cannot do what you're doing, that is, "storing temp path in the session" because that path is only valid for one request. 您无法执行正在执行的操作,即“在会话中存储临时路径”,因为该路径仅对一个请求有效。

From the PHP manual: 从PHP手册中:

The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed. 如果尚未移走或重命名文件,则在请求结束时将从临时目录删除该文件。

(Emphasis mine) (强调我的)

move_uploaded_file checks that a file has been uploaded to that page. move_uploaded_file检查文件是否已上传到该页面。 You are actually uploading the file to a different PHP script then storing in a session. 您实际上是在将文件上传到其他PHP脚本,然后存储在会话中。 Instead of using move_upload_file use rename. 而不是使用move_upload_file,而是使用重命名。

What is the output of $_SESSION['temp_img'][$key]['path'], also do you have permission to write to the web directory your placing the files. $ _SESSION ['temp_img'] [$ key] ['path']的输出是什么,您是否也有权将放置文件写入Web目录。 You may need to set it to 777 for some hosts to allow the webserver to write there. 对于某些主机,您可能需要将其设置为777,以允许Web服务器在此处进行写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM