My Blog
My Personal Blog
Now viewing all posts in PHP

December 12th 2009

For all you geeks, finding an extension, cross platform, because application/type doesn’t always work with $_FILES['file']['type'] cross platform.
The mime information is read differently, I ran into this problem on unix when somebody uploaded a pdf edited on a windows machine.
function findExt($f) {
$var = $f;
$explode = explode(‘.’, $var);
$num = count($explode);
$ext = strtolower($explode[$num - 1]);

return $ext;
}
Then call [...]

Read On No Comments

Restricting an input field to only numbers with preg_match_all() (PHP)

May 7th 2009

This is a pretty easy way to restrict a field to only numbers.
The \D in the preg match is short for [^0-9], which will match all characters, except 0-9.
I’m new to the regex, so there might be a better way to do this. But this works for me.

I like to do all the validating [...]

Read On No Comments


Recent Comments