muli-File Type Image Upload Script

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
redzonne
Forum Newbie
Posts: 8
Joined: Sun Mar 06, 2005 12:27 pm
Location: Los Angeles

muli-File Type Image Upload Script

Post by redzonne »

I have adapted my script to allow uploading of .png, .jpeg, .jpg and .gif instead of just .gif.

Yet, my script doesn't seem to accept anything other than .gif. Any suggestions?

Also, is it possible to restrict an image file dimension (example 100px x 125px)?

Code: Select all

<? 
if(isset( $Submit )) 
{ 
//If the Submitbutton was pressed do: 

$image_types = Array ('image/gif', 'image/jpeg', 'image/jpg', 'image/png');

if ((in_array($_FILES['imagefile']['type'], $image_types)) &&
($_FILES['imagefile']['size'] > 15000))
        {
    copy ($_FILES['imagefile']['tmp_name'], "ag_thumb/".$_FILES['imagefile']['name']) 
    or die ("Could not copy");
        echo '<table border="0" cellpadding="0" cellspacing="0" width="400">';
        echo '<tr><td><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td></tr>';
        echo '<tr><td><span class=psparkblu12><b>Name: </b>'.$_FILES['imagefile']['name'].' </span></td></tr>';
        echo '<tr><td><span class=psparkblu12><b>Size: </b>'.$_FILES['imagefile']['size'].' </span></td></tr>';
        echo '<tr><td><span class=psparkblu12><b>Type: </b>'.$_FILES['imagefile']['type'].' </span></td></tr>';
        echo '<tr><td><img src="/main_img/6px_spacer.gif" width="6" height="6" border="0"></td></tr>';
        echo '<tr><td><span class=psparkred12><b>Image Upload Complete...</b></span></td></tr>';
        echo '</table>';
        }
else 
        { 
            echo ""; 
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")"; 
        } 
} 
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

both questions are answered within getimagesize()
Post Reply