Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 510
Boris Avatar asked Feb 15 '11 12:02

Boris


People also ask

Which attribute is needed for file upload via a form in PHP?

Make sure that the form uses method="post" The form also needs the following attribute: enctype="multipart/form-data".

What is Tmp_name in PHP file upload?

tmp_name is the temporary name of the uploaded file which is generated automatically by php, and stored on the temporary folder on the server. name is the original name of the file which is store on the local machine.

Can we upload a file of any size to a PHP application depends on configuration?

Two PHP configuration options control the maximum upload size: upload_max_filesize and post_max_size . Both can be set to, say, “10M” for 10 megabyte file sizes. However, you also need to consider the time it takes to complete an upload.


1 Answers

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

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

...

$info = $_POST["info"];
like image 182
Pekka Avatar answered Oct 29 '22 22:10

Pekka