简体   繁体   中英

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

        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 :).

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.

为什么不使用表格发布?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM