php 上传文件 出错
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
if(is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"];
echo "$tmp_name ";
move_uploaded_file($tmp_name,'upload/' .$name);
}
?>
<form enctype="multipart/form-data" method="post" name="upform">
<input type="file" name="upfile"/>
<input type="submit" value="上传" />
</form>
</body>
</html>
错误提示:
D:\wamp\tmp\php101.tmp
Warning: move_uploaded_file(upload/QQ截图未命名.png) [function.move-uploaded-file]: failed to open stream: Invalid argument in D:\wamp\www\bbs\upfile.php on line 23
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\wamp\tmp\php101.tmp' to 'upload/QQ截图未命名.png' in D:\wamp\www\bbs\upfile.php on line 23 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
if(is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
$name = $upfile["name"];
$type = $upfile["type"];
$size = $upfile["size"];
$tmp_name = $upfile["tmp_name"];
echo "$tmp_name ";
move_uploaded_file($tmp_name,'upload/' .$name);
}
?>
<form enctype="multipart/form-data" method="post" name="upform">
<input type="file" name="upfile"/>
<input type="submit" value="上传" />
</form>
</body>
</html>
错误提示:
D:\wamp\tmp\php101.tmp
Warning: move_uploaded_file(upload/QQ截图未命名.png) [function.move-uploaded-file]: failed to open stream: Invalid argument in D:\wamp\www\bbs\upfile.php on line 23
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\wamp\tmp\php101.tmp' to 'upload/QQ截图未命名.png' in D:\wamp\www\bbs\upfile.php on line 23 展开
1个回答
展开全部
把上传的文件的文件名,改成全英文的试试。
更多追问追答
追问
嗯 谢谢 不过能问下为什么嘛 是不是我的程序 需要在哪加上什么 处理呢 如果只能上传纯英文名的文件 那还是没有解决根本问题啊
追答
你肯定是用的windows操作系统吧。
这是因为php字符编码和windows不同的问题,简体中文版的windows对文件名的命名一般使用gbk或gb2312编码。而php中的非ASCII字符串变量的值大多使用utf8编码(当然,这个默认值可以修改。。)。你需要将$name变量转换为gbk编码,才能在windows的文件系统中命名并存储下来。可以使用mb_convert_encoding函数来转换字符串的编码。
假设你的php是utf8编码,那么你将你的代码中
move_uploaded_file($tmp_name,'upload/' .$name);
这一行改成
move_uploaded_file($tmp_name,'upload/' .mb_convert_encoding($name,"gbk", "utf-8"));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询