html表单enctype = multipart / form-data

时间:2013-08-24 18:52:13

标签: php html5 web

您好我正在尝试创建一个将在某些Web示例之后加载图像的表单,但我无法加载图像。我正在处理运行apache的个人fedora盒子。是否有一些设置我必须与Apache做不同的事情? 这是我应该上传图片的表单脚本:

            <form name ="input" enctype="multipart/form-data" action = "addPhotograph.php" method = "get">
            <table>
               <tr>
                  <th>Title:</th> <td><input type="text" name ="photoname"></td>
               </tr>
               <tr>
               <th>Photograph:</th> <td><input type="file" id="file" name="file" accept="image/*"></td>
               </tr>
               <tr>
               <th>Photographer:</th><td><input type="" name="photographer"></td>
               </tr>
               <tr>
               <th>Genre:</th><td><input type = "" name="genre"></td>
               </tr>
            <table>   
               <input type="submit" value = "Submit">
            </form>

这是我的PHP脚本:

        <?php
        $uploaddir = '/var/www/html/photodb';
        $uploadfile = $uploaddir . basename($_FILES['file']['name']);

        echo '<pre>';
        if (move_uploaded_file($_FILES['file']['name'], $uploadfile)) {
            echo "File is valid, and was successfully uploaded.\n";
        } else {
            echo "Possible file upload attack!\n";
        }

        echo 'Here is some more debugging info:';
        print_r($_FILES);

        print "</pre>";
        ?>

当我通过表单添加图像时,php表单无法说“可能的文件上传攻击!” 我想这意味着文件无法移动或文件未上传?

我正在为我的大学作业做这件事任何回应或其他想法都非常感激:)。

2 个答案:

答案 0 :(得分:3)

将您的方法更改为POST:

<form name ="input" enctype="multipart/form-data" action = "addPhotograph.php" method = "post">

您无法通过GET方法发布文件。

答案 1 :(得分:0)

为什么不使用表格帖子?

<form name ="input" enctype="multipart/form-data" action = "addPhotograph.php" method = "post">
相关问题