gpt4 book ai didi

php - 验证上传的文件类型

转载 作者:行者123 更新时间:2023-11-29 14:10:11 26 4
gpt4 key购买 nike

为什么下面无法识别正在上传的图像(.jpg)?

我收到上传的文件不是图像!!!

$finfo = finfo_open(FILEINFO_MIME_TYPE, 'C:\xampp\php\extras\magic\magic.mime');
if(strpos(finfo_file($finfo, $_FILES['userfile']['tmp_name']),"image")===0) {

// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));

// put the image in the db...
// database connection
mysql_connect($host, $user, $pass) OR DIE (mysql_error());

// select the db
mysql_select_db ($db) OR DIE ("Unable to select db".mysql_error());

// our sql query
$sql = "INSERT INTO uploaded_images
(image, name)
VALUES
('{$imgData}', '{$_FILES['userfile']['name']}');";

// insert the image
mysql_query($sql) or die("Error in Query: " . mysql_error());
$msg='<p>Image successfully saved in database with id ='. mysql_insert_id().' </p>';
}
else
$msg="<p>Uploaded file is not an image.</p>";

最佳答案

如果您无权访问 GD 库,您可以简单地使用 getimagesize(),如果它不是图像,它将返回 false。 http://php.net/manual/en/function.getimagesize.php

关于php - 验证上传的文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13624975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com