|
Posted by Rik on 10/15/06 14:03
mantrid wrote:
> Hello
> Found this piece of code using preg_match to check file types during
> upload of files.
No, after uploading, unfortunately.
> $allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
> preg_match("/\." . $allowed_file_types . "$/i",
> $_FILES['uploadedfile']["name"])
>
> I understand the basic preg_match but am confused as to how the string
> pattern part is working i.e.
> "/\." . $allowed_file_types . "$/i"
>
> I need to understand it better as although it appears to work in
> other parts of my site, Im getting an error message on one page
>
> Warning: preg_match() expects parameter 2 to be string, array given in
> /home/iddsoftw/public_html/questiondbase/usersquestions.php on line 52
>
> Can anyone give a step by step explanation of what its doing
Your problem is not in the regex (which means: filename has to end on
..jpg/.jpeg etc.).
Your problem is in the $_FILES part.
If you upload 1 file, named uploadedfile, $_FILES['uploadedfile']['name']
contains the string with the name of that file. If however you upload more
files (several inputs named uploadedfile[] for instance),
$_FILES['uploadedfile']['name'] will contain an array of names of the
uploaded file. That array won't fit in preg_match, and you'll have to loop
in some way through the $_FILES array.
var_dump($_FILES) in the bugging script, and all will be clear I think.
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|