简体   繁体   中英

Appending Data to Uploaded File Using PHP

I'm making a PHP upload form, but need to add some additional data to each image based on what the user types in. For example, they choose the file to upload and type in the name, height, width, and price of that file, then hit submit. That information needs to be stored with the photo or appended to the metadata.

Here's what I have for submitFile.php:

<form enctype="multipart/form-data" action="Upload.php"
  method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000000" />

    Select a File: <input name="uploaded_file" type="file" /><br/>

    <input type="submit" value="Upload" />

And here's what I have for Upload.php:

<?php

$uploaddir = "uploads/images";
$uploadfile = $uploaddir.basename($_FILES['uploaded_file']['name']);

    echo "<pre style= font-size:20px>";

        if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$uploadfile))
    {
        echo "<b>File has been successfully uploaded!</b>.\n";
    }
        else{
        echo "<b>File upload failed!</b>.\n";
    }

echo '<br/>Here is some more debugging info:'."<br/>";
echo "Name:".$_FILES["uploaded_file"]["name"]."<br/>";
echo "File Type:".$_FILES["uploaded_file"]["type"]."<br/>";
echo "File Size:".($_FILES["uploaded_file"]["size"]/1024)." Kb<br/>";
echo "Temp File:".$_FILES["uploaded_file"]["tmp_name"]."<br/>";

echo "</pre>";

?>
</form>

For JPEGs (and maybe TIFFs ?), you should use something like this .

However, for PNGs , checkout this answer.

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