xyn Posted July 30, 2006 Share Posted July 30, 2006 I've got an image upload code.I want to check that the file IS an imageusing image/png, image/gif etc. how wouldi add it into this code?[code=php:0]<?PHPif(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] Quote Link to comment https://forums.phpfreaks.com/topic/16052-last-question-sorry/ Share on other sites More sharing options...
xyn Posted July 30, 2006 Author Share Posted July 30, 2006 edit: Is there a way using an array? Quote Link to comment https://forums.phpfreaks.com/topic/16052-last-question-sorry/#findComment-66120 Share on other sites More sharing options...
trq Posted July 30, 2006 Share Posted July 30, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16052-last-question-sorry/#findComment-66128 Share on other sites More sharing options...
xyn Posted July 31, 2006 Author Share Posted July 31, 2006 how would i use this? Quote Link to comment https://forums.phpfreaks.com/topic/16052-last-question-sorry/#findComment-66635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.