I can't upload my images!??!

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
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

I can't upload my images!??!

Post 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
Paul Arnold
Forum Contributor
Posts: 141
Joined: Fri Jun 13, 2008 10:09 am
Location: Newcastle Upon Tyne

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

Post 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.
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

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

Post 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.
Post Reply