Image upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glenn
Forum Newbie
Posts: 18
Joined: Fri Apr 19, 2002 7:42 am
Location: London, England (UK)

Image upload

Post by glenn »

I know someone else has posted a questions like this but I looked at that and that didn't help me. Iam trying to upload only files with a .gif / .jpg or .jpeg suffix ending. I have posted my code below, the only thing that will not work about it is that it keeps giving me the error message when I try to upload a .jpg ect. I think my eregi patten that I use to lookup the file siffix is wrong in some way. Could someone help me?

Thanks Glenn

<?php

if (($info == "") or ($services == "") or ($clients == "") or ($company == "") or ($home == "") or ($logoup == "")) {

print ("<center><BR><BR><BR><BR><BR>Sorry, data input not complete. <a href=both.html>click here</a> to re-enter the information.<BR><BR>Please ensure all required fields are completed before you submit.</center>");

} else {

if ($HTTP_POST_FILES['logoup']['size'] <=0)
{
print ("<center>Sorry no file found, please <a href=both.html>click here</a> to try again</center>");
} else {

if (!file_exists($company))
{
mkdir($company, 0777);
}

$temp = $HTTP_POST_FILES['logoup']['tmp_name'];
$dest = $HTTP_POST_FILES['logoup']['name'];

if (eregi ("(.)+\\.(jp(e){0,1}g$|gif$|png$)",$logoup)) {


copy($temp, "$company/$dest");

$mailto = "EMAILADDREESS";
$mailfrom = "From: SENDADRESS";
$subject = "UPLOAD";
$body = "NOTE : FILE TO BE DOWNLOADED!";

mail ($mailto, $subject, $body, $mailfrom);
print ("<center><BR><BR><BR>Thank You</center>");

} else {
print ("Please select a vaild logo file");
}

}
}
?>
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

when you want to provide a list of options for a regular expression you need to enclose them in square brackets -- []. I think you want something more like

Code: Select all

if (eregi( '.*\.&#1111;jpg|jpeg|gif|png]$',$logoup))
I would typically not use .* as the beginning match, but would explicitly list the allowed characters like

Code: Select all

if (eregi('^&#1111;-a-zA-Z0-9\._]*\.&#1111;jpg|jpeg|gif|png]$',$logoup))
The exact list of character you wish to allow will likely vary from this list. I don't beleive there is any reason to allow directory slashes in the user provided filename, so they should definately be disallowed.
Post Reply