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");
}
}
}
?>
Image upload
Moderator: General Moderators
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
I would typically not use .* as the beginning match, but would explicitly list the allowed characters like
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.
Code: Select all
if (eregi( '.*\.їjpg|jpeg|gif|png]$',$logoup))Code: Select all
if (eregi('^ї-a-zA-Z0-9\._]*\.їjpg|jpeg|gif|png]$',$logoup))