Page 1 of 1

photo upload problom

Posted: Tue Sep 02, 2008 12:04 am
by srisree
when user submit listings and try to upload pics for logo, the "logo.gif" is uploading file but "logo.jpg" and "logo.png" is error out with the following message:

Code: Select all

Only png, gif, or jpg !!!
sure that the logo size is within limit and the folder permision is right. Any suggestion?

Just posting the code here if anyone see anything wrong with this code below.
help me

Code: Select all

$domain = XOOPS_URL;
$path = './images/shots/'; //path to targetfolder
$path_after_domain = '/modules/' . $mydirname . '/images/shots/'; //path to targetfolder for use in url
$max_size = $xoopsModuleConfig['logo_maxfilesize']; //maximum filesize
$ferror = false;
if ((isset($_FILES['logoup'])) && (is_uploaded_file($_FILES['logoup']['tmp_name'])))
{
if ($_FILES['logoup']['size']>$max_size)
{
$ferror = _MD_ELOGOSIZE; // file too big
}
else
{
if (($_FILES['logoup']['type']=='image/gif') || ($_FILES['logoup']['type']=='image/png') || ($_FILES['logoup']['type']=='image/jpeg')) {
if (file_exists($path . $_FILES['logoup']['name'])) {
$ferror = _MD_ELOGOSAMENAME; // file exists
} else {
if (!copy($_FILES['logoup']['tmp_name'], $path .$_FILES['logoup']['name'])) {
$ferror = _MD_ELOGOTEMP;
}
}
} else {
$ferror = _MD_ELOGOTYPE; // wrong file type
}
}

Re: photo upload problom

Posted: Tue Sep 02, 2008 12:53 am
by eskio
Hi,

you have too much if statements. And I do not understand why you have 2 paths to upload your photos (path to targetfolder)?

I will give you my code (I have only 2 if-else statements).

Code: Select all

$PhotoGood = false;  // initalization - is not a good photo
$FPhoto = $_FILES['filePhoto']; 
if ($FPhoto['size'] < $MaxPhotoSize){
    if (($FPhoto['type'] == 'image/gif') || ($FPhoto['type'] == 'image/jpeg') || ($FPhoto['type'] == 'image/png')){
        // Good photo
        ............ // action to take
    } else {
        print "Invalid photo type!<br />";      
    } // if (($FPhoto['type'] == 'image/gif') OR ($FPhoto['type'] == 'image/jpeg') OR ($FPhoto['type'] == 'image/png'))
} else {// if ($FPhoto['size'] < $MaxPhotoSize)
        print "The photo '".$FPhoto['name']."' is too big (".ceil($FPhoto['size']/1000)." Kb)!<br />Please resize the photo.<br />";
} // if ($FPhoto['size'] < $MaxPhotoSize)
 

Re: photo upload problom

Posted: Tue Sep 02, 2008 2:54 am
by DaiWelsh
Chekc the value of $_FILES['logoup']['type'] when you get the error message, my guess would be it is not matching your expectations. For example I know I have seen some jpg files in the past that show as type image/pjpg not image/jpg. Depending on what you are doing with the uploaded files, arguably you are better off checking the extension of the file rather than the image type as this is what will determine how the web server serves them later, but assuming you do want to check image type it is probably just a case of extending the list to allow variations.

Try

http://www.google.co.uk/search?sourceid ... age%2fpjpg

to get suggestions for what is likely to come through.

HTH,

Dai

Re: photo upload problom

Posted: Tue Sep 02, 2008 3:53 am
by onion2k
Never trust $_FILES['upload']['type']. It's data from the user and could be wrong, fake, or an attempt to hack your site. Check the file itself. For images that's easy, just use getimagesize().

Re: photo upload problom

Posted: Tue Sep 02, 2008 3:54 pm
by webxan
try adding more types like

'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'