move_uploaded_file() 无法打开流:没有这样的文件或目录

2023-02-22php开发问题
4

本文介绍了move_uploaded_file() 无法打开流:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经完成了你的标准检查(目录是否在那里,权限设置是否足够宽松),而且我很确定我已经涵盖了你标准的愚蠢的人类技巧.这是失败的代码:

I've done your standard checks (is the directory there, are lax enough permissions set), and I'm pretty sure I've covered your standard stupid human tricks. Here's the code that's failing:

move_uploaded_file($_FILES['image1']['tmp_name'], "/public_html/flashsale/assets/img/products/T".$_FILES['image1']['name']);

目录在那里 - 我从 FileZilla 复制了路径.我什至在 FileZilla 和 HostGator 控制面板上的文件管理器中将权限设置为 777.此代码生成两个警告:

The directory is there - I copied the path from FileZilla. I even set the permissions to 777, both in FileZilla and in the file manager on the HostGator control panel. This code generates two warnings:

留言:move_uploaded_file(/public_html/flashsale/assets/img/products/Tsirloin.jpg)[function.move-uploaded-file]:无法打开流:没有那个文件或目录

Message: move_uploaded_file(/public_html/flashsale/assets/img/products/Tsirloin.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory

消息:move_uploaded_file() [function.move-uploaded-file]:无法将/tmp/phpI5GZ3S"移动到'/public_html/flashsale/assets/img/products/Tsirloin.jpg'

Message: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpI5GZ3S' to '/public_html/flashsale/assets/img/products/Tsirloin.jpg'

按照这个顺序.所以,文件正在上传,目录存在并设置为777,我还能缺少什么?

In that order. So, the file is being uploaded, the directory exists and is set to 777, what else could I be missing?

推荐答案

你不需要把完整的目录放到文件中.尝试从您的链接中删除 /public_html/flashsale/ 并查看它是否有效.另外文件不需要777权限,我自己上传文件到755权限的文件夹.

you do not need to put the full directory to the file. try to remove /public_html/flashsale/ from your link and see if that will work. In addition, the file does not need to have 777 permission, I myself upload files to folders with 755 permissions.

此外,您可以在目标目录中使用 getcwd();.该函数将为您提供移动文件所需的目录.来源

also, you can use getcwd(); in the directory your aiming to. the function will give you the directory that you need to use for moving your file. source

这篇关于move_uploaded_file() 无法打开流:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17