Jump to content


Photo

Last question... sorry :]


  • Please log in to reply
3 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 30 July 2006 - 09:34 PM

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?

<?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>";
} 
?>


#2 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 30 July 2006 - 09:38 PM

edit: Is there a way using an array?

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 July 2006 - 10:02 PM

Your most reliable method is to use getimagesize. This will return false if the file isn't a valid image.

#4 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 31 July 2006 - 09:04 PM

how would i use this?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users