简单的文件上传脚本(simple file upload script)
我写了一个简单的文件上传脚本,但它给了我未定义索引file1的错误。
<html> <body> <form method="post"> <label for="file">Filename:</label> <input type="file" name="file1" id="file1" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> <?php if(isset($_POST['submit'])) { if ($_FILES["file1"]["error"] > 0) { echo "Error: " . $_FILES["file1"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file1"]["name"] . "<br />"; echo "Type: " . $_FILES["file1"]["type"] . "<br />"; echo "Size: " . ($_FILES["file1"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file1"]["tmp_name"]; } } ?>代码中有什么问题?
I have written a simple file upload script but it gives me the error of undefined index file1.
<html> <body> <form method="post"> <label for="file">Filename:</label> <input type="file" name="file1" id="file1" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> <?php if(isset($_POST['submit'])) { if ($_FILES["file1"]["error"] > 0) { echo "Error: " . $_FILES["file1"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file1"]["name"] . "<br />"; echo "Type: " . $_FILES["file1"]["type"] . "<br />"; echo "Size: " . ($_FILES["file1"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file1"]["tmp_name"]; } } ?>What is the problem in code?
最满意答案
您的<form>元素中缺少enctype="multipart/form-data" 。
You lack enctype="multipart/form-data" in your <form> element.
更多推荐
发布评论