Reply to Re: preg_match explanation

Your name:

Reply:


Posted by mantrid on 10/15/06 15:26

Hi

silly me, I am using a loop and I see now that I left the [$i] of the end of
['uploadedfile']["name"] in the preg_match. It works now, but I'd still like
to know how the pattern variable is working in the code.

Ian

"Rik" <luiheidsgoeroe@hotmail.com> wrote in message
news:55755$45323f90$8259c69c$15987@news1.tudelft.nl...
> 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
>
>

[Back to original 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

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