简体   繁体   English

move_uploaded_file中的错误

[英]error in move_uploaded_file

I'm trying upload an image using: 我正在尝试使用以下方式上传图片:

$sourcePath = $_FILES['file']['tmp_name'];
$targetPath = "upload/".$_FILES['file']['name'];

move_uploaded_file($sourcePath,$targetPath) ;

but there is always an error like this: 但是总会有这样的错误:

Warning:move_uploaded_file(upload/13709_965665460118582_8676485775333023105_n.jpg): failed to open stream: No such file or directory in C:\\xampp\\htdocs\\AjaX\\ajax_php_file.php on line 23 警告:move_uploaded_file(upload / 13709_965665460118582_8676485775333023105_n.jpg):无法打开流:第23行的C:\\ xampp \\ htdocs \\ AjaX \\ ajax_php_file.php中没有此类文件或目录

Warning: move_uploaded_file(): Unable to move 'C:\\xampp\\tmp\\php3C97.tmp' to 'upload/13709_965665460118582_8676485775333023105_n.jpg' in C:\\xampp\\htdocs\\AjaX\\ajax_php_file.php on line 23 警告:move_uploaded_file():无法在23行的C:\\ xampp \\ htdocs \\ AjaX \\ ajax_php_file.php中将'C:\\ xampp \\ tmp \\ php3C97.tmp'移动到'upload / 13709_965665460118582_8676485775333023105_n.jpg'

What am I gonna do with this thing? 我要怎么办?

Make sure that 确保

  • the file was uploaded without an error ( php manual ) 文件上传没有错误( php manual
  • the destination directory exists and is writable 目标目录存在并且可写

The anwser is right in front of you: 答案就在您的面前:

Warning:move_uploaded_file(upload/13709_965665460118582_8676485775333023105_n.jpg): failed to open stream: No such file or directory in C:\\xampp\\htdocs\\AjaX\\ajax_php_file.php on line 警告:move_uploaded_file(upload / 13709_965665460118582_8676485775333023105_n.jpg):无法打开流:C:\\ xampp \\ htdocs \\ AjaX \\ ajax_php_file.php中没有这样的文件或目录

The warning clearly states "No such file or directory", this is your issue, 该警告明确指出“没有这样的文件或目录”,这是您的问题,

the directory <script location>/upload does not exist, what you may want to do is use $_SERVER['DOCUMENT_ROOT'] to get an absolute file path for your destination location. 目录<script location>/upload不存在,您可能想使用$_SERVER['DOCUMENT_ROOT']获取目标位置的绝对文件路径。

Typically the DOCUMENT_ROOT value is the root of your domain as a filepath string, such that $_SERVER['DOCUMENT_ROOT'] is the same location in the file structure as http://www.yourwebdomain.com/<here> . 通常, DOCUMENT_ROOT值是DOCUMENT_ROOT路径字符串的域的根,因此$_SERVER['DOCUMENT_ROOT']在文件结构中的位置与http://www.yourwebdomain.com/<here>

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

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