我正在编写一个脚本,它将从用户输入上传文件,将其大小调整为缩略图,并将两个新文件名添加到数据库中.
但是,我不能为我的生活弄清楚如何让PHP检测图像的MIME类型,然后将其提供给标题.这是代码,我已经发表评论,试图让它尽可能清晰:
$picture = $_FILES['picture']['name'];
/*original file location*/
$file = 'picture/'.$picture.'';
/*save thumbnail location*/
$save = 'thumb/tn-'.$picture.'';
/*append thumbnail filename with tn-*/
$thumb = 'tn-'.$picture.'';
/*get original file size*/
list($width, $height) = getimagesize($file);
/*get image MIME type*/
$size = getimagesize($file);
$fp = fopen($file, "r");
if ($size && $fp)
{
header("Content-type:".$size['mime']);
fpassthru($fp);
exit;
}
else
{
echo 'Error getting filetype.';
}
/*define thumbnail dimensions*/
$modwidth = 300;
$modheight = 200;
/*check to see if original file is not too small*/
if …Run Code Online (Sandbox Code Playgroud)