Frage

on my website I want to allow people to upload guitar pro files. Apparently there is no specific MIME type for these (I tested and it gave me 'application/octet-stream'). Is there a way to check and be 100% sure the files are guitar pro files and not something else? Thanks

War es hilfreich?

Lösung

Read the first bytes from the uploaded file. For example this is how I used to check uploaded files when I was creating similar functionality.

$f = fopen($_FILES['tmp_name'], "rb");
fseek($f, 1);
$in = fgets($f, 19);
fclose($f);

if ($in == 'FICHIER GUITAR PRO') { ... }

So reading chars from 1st to 19th would give me string 'FICHIER GUITAR PRO'. This approach worked for me for gp4 files. Also I used to check files extensions. However keep in mind that there is no real check you can perform in order to filter malicious uploads since faking this first bytes as well as extension is pretty easy. So there should always be some additional moderation of all uploaded files.

Andere Tipps

You should parse the file and see if the version string is correct:

http://dguitar.sourceforge.net/GP4format.html
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top