Page 1 of 1

I can't upload my images!??!

Posted: Fri Sep 12, 2008 10:55 am
by cap2cap10
Her is the code:

Code: Select all

<?php
include 'opendb.php';
  if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
    $filetype = $_FILES['userfile']['type'];
    $userID = $_POST['userID'];
 
    $target_path = "uploads/";
 
    $image_type = basename($_FILES['userfile']['type']);
    if ($image_type == 'jpeg')
    {
        $image_type = 'jpg';
    }
    $target_path = $target_path.$userID.'.'.$image_type;
 
    $possiblefiletypes = array('image/jpg','image/jpeg', 'image/gif', 'image/png');
 
    if (!in_array($filetype, $possiblefiletypes))
    {
        echo'<b><font color=#FF0000>Sorry, this file type is not supported.</b></font>';
    }
 
    else
    {
        if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path))
        {
            echo 'The file '.basename( $_FILES['userfile']['name']).' has been uploaded.<br>';
            $query = "UPDATE js_resume SET image_type = '$filetype' WHERE userID = '$userID'";
            mysql_query($query) or die(mysql_error());
        }
        else
        {
            echo 'There was an error uploading the file!<br><br>';
        }
    }
}
 
include 'closedb.php';
 
 
?>
 
:banghead:

I keep getting "Sorry, this file type is not supported." for my jpg images?!?
what is wrong with this code or am I missing something?
Thanks in advance,

Batoe

Re: I can't upload my images!??!

Posted: Fri Sep 12, 2008 11:31 am
by Paul Arnold
Make sure your file extensions are not in CAPS. i.e: Image.JPG.

Also worth checking your folder permissions while you're at it.

Re: I can't upload my images!??!

Posted: Fri Sep 12, 2008 12:24 pm
by maliskoleather
i wouldn't ever rely on the file extension to check the type, expecially when in reference to uploaded files... It isn't always right, and can be manipulated by the end user.

look into something like http://us2.php.net/manual/en/function.m ... t-type.php or http://us2.php.net/manual/en/ref.fileinfo.php to get the mimetype.