Reputation: 59
I want to upload a .csv file in PHP and want to ensure that the file is in .csv format. suppose if someone upload image file by changing the extension.
Upvotes: 1
Views: 101
Reputation: 3953
If it's a CSV, you can use fgetcsv()
and check for null
or false
.
$handle = fopen("uploaded_file.csv");
if(!($csvContent = fgetcsv($handle) == false)) {
//invalid CSV
}
Upvotes: 1