一个关于文件上传的页面.遇到错误.求大神指导指导

WBOY
Release: 2016-06-23 14:05:37
Original
925 people have browsed it

upload.

upload your file

chose your file:
describe:
owner:
submit:

Copy after login

这个是用来前台的页面调用下面的php.
"; echo "clicktherereturn!";}else { $filepath="upload/"; $name=$filepath.$_FILES["upload"]["name"]; while (file_exists($name)) { $temp=explode(".", $name); $name=$temp[0]."0".".".$temp[1]; } if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $name)) { if ($_POST["owner"]) { $owner=$_POST["owner"]; } else { $owner="NULL"; } if ($_POST["describe"]) { $describe=$_POST["describe"]; } else { $describe="NONE"; } $time=date("y-m-d H:m:s"); $content=$_FILES["upload"]["name"]."||".$owner."||".$describe."||".$time."\n"; file_put_contents("record.dat", $content.FILE_APPEND); echo "name:".$_FILES["upfile"]["name"]; echo "

"; echo "is upload successfull.

"; echo "clicktherereturn!"; } else { echo "upload error!

"; echo "fail!

"; echo "clicktherecheck!"; }}?>

Copy after login

问题就在于上传之后,提示文件上传成功,但是upload文件夹里面文件名是0的倍数,而且没有文件格式..这个是怎么回事呢?


提示的错误就是下面这些..
Notice: Undefined index: upfile in D:\phpnow\htdocs\b\up_back.php on line 2

Notice: Undefined index: upload in D:\phpnow\htdocs\b\up_back.php on line 10

Notice: Undefined offset: 1 in D:\phpnow\htdocs\b\up_back.php on line 14

Notice: Undefined index: upload in D:\phpnow\htdocs\b\up_back.php on line 35
name:10.jpg


回复讨论(解决方案)

这一行 $name=$filepath.$_FILES["upload"]["name"];
第一个文件上传的name="file" , 没有"upload" 啊.

move_uploaded_file($_FILES["upfile"]["tmp_name"], $name) 后面参数没有带路径

move_uploaded_file($_FILES["upfile"]["tmp_name"], $name) 后面参数没有带路径

他的$name=$filepath.$_FILES["upfile"]["name"];就是这个

1.
if (!$_POST["upfile"]&&$_FILES["upfile"]["name"]=="")
==>
if ($_FILES["upfile"]["name"]=="") //这样就能判断是否选择文件了

2.
$name=$filepath.$_FILES["upload"]["name"];
==》
$name=$filepath.$_FILES["upfile"]["name"];

3. 如果你的文件存在了。while循环不就成了死循环了吗,可以改为:
if(file_exists($name))
{
$temp=explode(".", $name);
$name=$temp[0]."0".".".$temp[1];
}
4. $content=$_FILES[" upfile"]["name"]."||".$owner."||".$describe."||".$time."\n";

1.
if (!$_POST["upfile"]&&$_FILES["upfile"]["name"]=="")
==>
if ($_FILES["upfile"]["name"]=="") //这样就能判断是否选择文件了

2.
$name=$filepath.$_FILES["upload"]["name"];
==》
$name=$filepath.$_……
谢谢你的帮助,根据这样修改后,确实完成了模块功能...万分感谢.

这一行 $name=$filepath.$_FILES["upload"]["name"];
第一个文件上传的name="file" , 没有"upload" 啊.
恩,确实这里有点毛病.谢谢你

1.
if (!$_POST["upfile"]&&$_FILES["upfile"]["name"]=="")
==>
if ($_FILES["upfile"]["name"]=="") //这样就能判断是否选择文件了

2.
$name=$filepath.$_FILES["upload"]["name"];
==》
$name=……
大神级人物 受教了

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
Latest Issues
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!