photo upload problom

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
srisree
Forum Newbie
Posts: 3
Joined: Fri Aug 22, 2008 5:41 am

photo upload problom

Post 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
}
}
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: photo upload problom

Post 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)
 
DaiWelsh
Forum Commoner
Posts: 36
Joined: Wed Jan 08, 2003 9:39 am
Location: Derbyshire, UK

Re: photo upload problom

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: photo upload problom

Post 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().
webxan
Forum Newbie
Posts: 3
Joined: Tue Sep 02, 2008 3:32 pm

Re: photo upload problom

Post by webxan »

try adding more types like

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