Php 用户可以提交带有照片的数据。但在这里我可以';t检查图像内容。如何使用mime在此处检查
您可以在PHP中使用Php 用户可以提交带有照片的数据。但在这里我可以';t检查图像内容。如何使用mime在此处检查,php,postgresql,mime-types,Php,Postgresql,Mime Types,您可以在PHP中使用getimagesize函数。如果文件是有效图像,前两个参数将是宽度/高度。您可以检查这些数字是否可以接受(例如,这将接受宽度/高度在128-2048像素之间) 在移动上传的文件后插入以下代码: <?php $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if (((
getimagesize
函数。如果文件是有效图像,前两个参数将是宽度/高度。您可以检查这些数字是否可以接受(例如,这将接受宽度/高度在128-2048像素之间)
在移动上传的文件后插入以下代码:
<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$imagepath = "propertyimages/".(rand()) . $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], $imagepath);
$db = pg_connect("host=localhost port=5432 dbname=ohms user=postgres password=padmin");
$s="select dcode from dept where dname='$_POST[select]'";
$s1=pg_query($s);
$row=pg_fetch_array($s1);
$row[0];
$r = pg_fetch_row($s1);
$query = "INSERT INTO nsr VALUES ('$_POST[text1]','$_POST[text2]',
'$_POST[textarea]','$row[0]','$_POST[textfield3]', '$_POST[text5]','$_POST[text6]','$_POST[text7]','$_POST[text8]','$_POST[textfield]','$_POST[text10]','$_POST[ref_phno]','$d','".$imagepath."')";
$result = pg_query($query);
}}
$arr=getimagesize($imagepath);
如果($arr[0]>=128&&$arr[1]>=128&&$arr[0]您易受攻击。一般来说,您不想将原始二进制图像数据保存在数据库中。很少有使用案例证明这一点,而且很多使用案例使其成为一大难题。
$arr = getimagesize( $imagepath );
if( $arr[0] >= 128 && $arr[1] >= 128 && $arr[0] <= 2048 && $arr[1] <= 2048 )
{
// valid image
}
else
{
// error
}