Page 1 of 1

determine if file name has 2 dots in it

Posted: Sun Oct 10, 2010 8:56 pm
by Smudly
My uploader allows the following file formats:

jpg
pdf
gif
png

I tested that if someone was to name a file configure.php.jpg, my uploader allows it to upload

I want to do a check to see if the user has 2 extensions, and if so it will not allow them to upload.

I was thinking of just checking if the file name has two "." (dots) in the name. What function could I use to do this?

Or .. is there a better way?

Re: determine if file name has 2 dots in it

Posted: Sun Oct 10, 2010 11:35 pm
by requinix
For simplicity's sake, I'd use substr_count.

Re: determine if file name has 2 dots in it

Posted: Mon Oct 11, 2010 1:45 pm
by McInfo
Why would it matter if a file name has two dots? If you're worried about the content of a file, check the content, not the file name. Disallowing "configure.php.jpg" but allowing "configure.jpg" does not prevent someone from uploading a file containing PHP. If you want files named a certain way, rename them. Why cause trouble for users who want to upload files with names like "version_1.0.gif", "date_2010.10.11.png", or "forums.devnetwork.net.jpg"?