简单的文件上传脚本(simple file upload script)

编程入门 行业动态 更新时间:2024-10-26 23:27:34
简单的文件上传脚本(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.

更多推荐

本文发布于:2023-07-08 00:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1070184.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   文件上传   简单   simple   upload

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!