I'm using the following php code to upload a csv file. I want to use a good validation and not only via mime type or file extension. How can I do that?
if (isset($_POST['submit'])) {
$isfileok = false;
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
$isfileok = true;
}
if($isfileok){
//do something
}
}
You can look for patterns within the file content to determine the type. We solved this exact problem in a project I worked on using mime magic detection functionality in Tika. https://tika.apache.org/1.1/detection.html
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.