How do I really know if I am passing a file to the server, via a file upload option?
i) I use a form as follows:
<form name = "someForm" id = "someForm" method = "post" action = "saveFile.php">
<input type = "file" name = "upload1" id = "upload1" />
<input type = "file" name = "upload2" id = "upload2" />
<input type = "file" name = "upload3" id = "upload3" />
<input type = "submit" id = "btnSubmit" value = "Submit" />
</form>
ii) In saveFile.php, I use:
say:
echo $_FILES['upload1']["size"];
apart from others, but I get an Undefined index: upload1 error, but not when, I use:
echo $_POST['upload1']; //returns filename
You need to specify the <form>
enctype to "multipart/form-data"
:
<form enctype = "multipart/form-data" name = "someForm" id = "someForm" method = "post" action = "saveFile.php">
<input type = "file" name = "upload1" id = "upload1" />
<input type = "file" name = "upload2" id = "upload2" />
<input type = "file" name = "upload3" id = "upload3" />
<input type = "submit" id = "btnSubmit" value = "Submit" />
</form>
<form name="someForm" id="someForm" method="post"
action="saveFile.php" enctype="multipart/form-data">
Enctype is required for upload of files.
You can access them by $_FILES
not $_POST
, nor $_GET
:
echo $_FILES['upload1']['size'];
Files are saved in:
print_r($_FILES); // NOT IN 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.