上传文件报错,该如何解决

WBOY
Release: 2016-06-13 11:47:19
Original
1694 people have browsed it

上传文件报错
有的文件上传就没问题,有的文件上传就会报错比如Warning: move_uploaded_file(D:/xampp/htdocs/ca/doc/新.txt): failed to open stream: Invalid argument in D:\xampp\htdocs\ca\do_upload.php on line 22

Warning: move_uploaded_file(): Unable to move 'D:\xampp\tmp\php3BF8.tmp' to 'D:/xampp/htdocs/ca/doc/新.txt' in D:\xampp\htdocs\ca\do_upload.php on line 22
Stored in: D:/xampp/htdocs/ca/doc/新.txt
这里的line22是下面代码的第13行
如果把这个txt的名字改成新建文本文档的话就没问题...这是为啥啊

<?php<br />if ($_FILES["upload_file"]["error"] > 0)<br />    {<br />    echo "Return Code: " . $_FILES["upload_file"]["error"] . "<br />";<br />    }<br />  else<br />    {<br />    echo "Upload: " . $_FILES["upload_file"]["name"] . "<br />";<br />    echo "Type: " . $_FILES["upload_file"]["type"] . "<br />";<br />    echo "Size: " . ($_FILES["upload_file"]["size"] / 1024/1024) . " MB<br />";<br />    echo "Temp file: " . $_FILES["upload_file"]["tmp_name"] . "<br />";<br /><br />      move_uploaded_file($_FILES["upload_file"]["tmp_name"],<br />      "D:/xampp/htdocs/ca/doc/" . $_FILES["upload_file"]["name"]);<br />      echo "Stored in: " . "D:/xampp/htdocs/ca/doc/" . $_FILES["upload_file"]["name"];<br />    }<br />	$name=$_FILES["upload_file"]["name"];<br />	$size=floor($_FILES["upload_file"]["size"] / 1024/1024 )."MB";<br />	$loc="doc/" . $_FILES["upload_file"]["name"];<br />	echo "<br/>";<br />?>
Copy after login

------解决方案--------------------
你是说将 新.txt => 新建文本文档.txt  没问题么?
------解决方案--------------------
D:/xampp/htdocs/ca/doc/新.txt 是目录
------解决方案--------------------
确定 新.txt 新建文本文档.txt都是文件
------解决方案--------------------
测试了一下
显然你的表单页是 utf-8 的,所以 $_FILES["upload_file"]["name"] 也是 utf-8 的
于是在生成文件时就出错了
你可观察一下:凡是文件名中的中文字符是偶数个时都不会出错

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!