douke9545 2013-08-24 18:52
浏览 48
已采纳

html表单enctype = multipart / form-data

Hi I'm trying to create a form that will load images following some web examples but I can't get the images to load. I'm working on my personal fedora box running apache. Is there some settings that I have to do differently with Apache? Here's my form script that should be uploading image:

            <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>

And Here's my PHP script:

        <?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.
";
        } else {
            echo "Possible file upload attack!
";
        }

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

        print "</pre>";
        ?>

When I add an image through the form the php form fails saying "Possible file upload attack!" I guess this means either the file was not able to be moved or the file was not uploaded?

I'm doing this for my college assignment any response or other idea is dearly appreciated :).

  • 写回答

2条回答 默认 最新

  • dongyan7876 2013-08-24 18:54
    关注

    Change your method to POST:

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

    You cannot post your files via GET method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况