简单的文件上传脚本 [英] simple file upload script

查看:157
本文介绍了简单的文件上传脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个简单的文件上传脚本,但它给了我未定义索引file1的错误。

 < html> 
< body>
< form method =post>
< label for =file>文件名:< / label>
< input type =filename =file1id =file1/>
< br />
< input type =submitname =submitvalue =Submit/>
< / form>
< / body>
< / html> ($ _BIL [file1] [error]> 0){
<?php
if b $ b回显错误:。 $ _FILES [file1] [error]。 < br />;
} else {
echoUpload:。 $ _FILES [file1] [name]。 < br />;
回显类型:。 $ _FILES [file1] [type]。 < br />;
回声大小:。 ($ _FILES [file1] [size] / 1024)。 Kb< br />;
回声存储在:。 $ _FILES [ 文件1] [ tmp_name的值];
}
}
?>

代码中的问题是什么?

< form> enctype =multipart / form-data c $ c>元素。


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?

解决方案

You lack enctype="multipart/form-data" in your <form> element.

这篇关于简单的文件上传脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆