I am currently using this PHP code for upload function. I need to know how to add some file type validation for 1)extension, 2)file size limit and 3)to check that there is actually a file selected to upload.
Thanks for any help.
<?php
if(isset($_POST['submit'])){
if(count($_FILES['upload']['name']) > 0){
//Loop through each file
for($i=0; $i<count($_FILES['upload']['name']); $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if($tmpFilePath != "tmp/"){
//save the filename
$shortname = $_FILES['upload']['name'][$i];
//save the url and the file
$filePath = "uploads/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $filePath)) {
$files[] = $shortname;
//insert into db
//use $shortname for the filename
//use $filePath for the relative url to the file
}
}
}
}
header('Location: http://localhost/FloodMap/report.html');
exit;
}
?>