Reputation: 6688
I have this basic upload code:
<form action="upload.php" method="post" >
<input type="file" name="file" value="" />
<input type="submit" name="submit" value="Go" />
</form>
<?php
if(isset($_POST['submit'])){
echo '<h3>Post test: </h3>';
var_dump($_POST);
$csv = array();
if(isset($_FILES["file"])) {
//if there was an error uploading the file
if($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else {
//Print file details
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
}
}
else {
echo "No file selected <br />";
}
}
I keep getting "No file selected" which is the else fallback of isset($_FILES['file']
.
Would there be something in my php.ini file that I would need to set to allow me to upload files to a temp location? Is there something I need to do, other than submitting the form to set the file to $_FILES
?
Upvotes: 0
Views: 299
Reputation: 219824
You're missing the enctype="multipart/form-data"
attribute in the form tag:
<form action="upload.php" method="post" enctype="multipart/form-data">
Upvotes: 3