Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

Last question... sorry :]

Recommended Posts

I've got an image upload code.
I want to check that the file IS an image

using image/png, image/gif etc. how would
i add it into this code?

[code=php:0]<?PHP

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

include 'conf.php';
$query = "INSERT INTO images (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');

echo "<br>File $fileName uploaded<br>";
}
?>
[/code]

Share this post


Link to post
Share on other sites
edit: Is there a way using an array?

Share this post


Link to post
Share on other sites
Your most reliable method is to use [url=http://php.net/getimagesize]getimagesize[/url]. This will return false if the file isn't a valid image.

Share this post


Link to post
Share on other sites
how would i use this?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.