note 92025 deleted from features.file-upload by danbrown

From: Date: Mon, 06 Jul 2009 12:28:55 +0000
Subject: note 92025 deleted from features.file-upload by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157961@lists.php.net to get a copy of this message
Note Submitter: alan at projecthuddle dot com ---- I've looked for an easy way to tell if there is a CSV extension. In the end I used: $filename = $_FILES['userfile']['name']; $filename = strtolower($filename) ; $returns = strrchr($filename,".csv"); if ($returns != ".csv"){ echo"fail"; } So this gets the file name converts it to lowercase finds the first occurance of .csv and then returns that and everything after it I then check that $returns only includes .csv If the file name had filename.csv.inc $returns would be .csv.inc and so it would fail. Only those with CSV extision pass this test. It'd be pretty easy to adjust the function to do multiple file types. I haven't tried it but something like this should work: $filename = $_FILES['userfile']['name']; $filename = strtolower($filename) ; $returns = strrchr($filename,"."); switch ($returns ) { case ".txt": echo "txt found"; break; case ".csv": echo "csv found"; break; case ".png: echo "png found"; break; default: echo "No valid file format found"; }

« previous php.notes (#157961) next »