Is it possible to send additional parameters when uploading a file in PHP?

Boris picture Boris · Feb 15, 2011 · Viewed 13.2k times · Source

I am initializing file upload using the following HTML:

<form enctype="multipart/form-data" action="PHPScripts/upload.php" method="POST">
    <input type="file" id="browseButton" name="image" onchange="this.form.submit();" />
</form>

Upload.php script looks like this:

<?php
$file = $_FILES["image"];
$filepath = $file["name"];
$filetmp = $file["tmp_name"];
$filesize = $file["size"];
$filename = basename($filepath);
$filetype = substr($filename, strrpos($filename, ".") + 1);
...
?>

I need to pass one more parameter to my php script, but I don't know how. HTTP method is POST (as can be seen in the code above), but where should I put the parameter? Is that even possible? Thanks for clarifying this to me.

Answer

Pekka picture Pekka · Feb 15, 2011

Just add another input element of your choice. No additional magic required.

 <input type="hidden" name="info" value="Test">

...

$info = $_POST["info"];