一个关于文件上传的页面.遇到错误.求大神指导指导
<!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=gb2312" /><title>upload.</title><style type="text/css"><!--.STYLE2 { font-family: "宋体"; font-weight: bold;}--></style></head><body><style type="text/css"><!--tr,td{font-size:10px}--></style><center> <h1 id="upload-nbsp-your-nbsp-file">upload your file</h1> <p> <table border="1" cellspacing="0" cellpadding="1" bordercolordark="#ffffff" bordercolorlight="#0000ff" width="400"> <form action="up_back.php" method="post" enctype="multipart/form-data"> <tr bgcolor="#ccccff"> <td>chose your file:</td> <td><input type="file" name="upfile" size=32 /></td> </tr> <tr> <td>describe:</td> <td><input type="text" name="describe" size="42" /></td> </tr> <tr> <td>owner:</td> <td><input type="text" name="owner" size="42" /></td> </tr> <tr> <td>submit:</td> <td><center><input type="submit" value="submit" /></center></td> </tr> </form> </table> </p></center> </body></html>
这个是用来前台的页面调用下面的php.
<?phpif (!$_POST["upfile"]&&$_FILES["upfile"]["name"]==""){ echo "no file<p>"; echo "click<a href=\"up_forward.html\">there</a>return!";}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 "<p>"; echo "is upload successfull.<p>"; echo "click<a href=\"up_forward.html\">there</a>return!"; } else { echo "upload error!<p>"; echo "fail!<p>"; echo "click<a href=\"index.php\">there</a>check!"; }}?>
问题就在于上传之后,提示文件上传成功,但是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=……
大神级人物 受教了

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
