You are here: Re: preg_match explanation « PHP Programming Language « IT news, forums, messages
Re: preg_match explanation

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация