ishtiaq
ishtiaq

Reputation: 59

how to validate file content in php if someone change the extension of the file and uploadt it?

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

Answers (1)

Realitätsverlust
Realitätsverlust

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

Related Questions