This question already has an answer here:
I am trying to upload a CSV file to a server with a form but I keep getting a error. Would anyone be able to tell me why the file does not want to upload.
HTML code:
<form action="upload.php" method="post" enctype="multipart/form-data">
Select CSV file to upload
<input type="file" accept=".csv">
<input type="submit" value="Upload File" name="submit">
</form>
PHP code:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Allow certain file formats
if($fileType != "csv" ) {
echo "Sorry, only CSV files are allowed. ";
}
else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
?>
</div>