gpt4 book ai didi

php - 用户可以提交带有照片的数据。但是我这里无法查看图片内容。如何使用mime查看这里

转载 作者:行者123 更新时间:2023-11-29 13:28:54 25 4
gpt4 key购买 nike

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

tish 是一个注册页面的代码。用户可以用图像提交数据。这里用户可以提交各种图像扩展名。但是想要插入内容为图像的主机图像。而不是带有 .jpg 扩展名的 txt 如何这样做。请帮忙

最佳答案

您可以在 PHP 中使用 getimagesize 函数。如果文件是有效图像,前两个参数将是宽度/高度。您可以检查这些数字是否可接受(例如,这将接受宽度/高度在 128-2048 像素之间)。

move_uploaded_file之后,插入这段代码:

$arr = getimagesize( $imagepath );
if( $arr[0] >= 128 && $arr[1] >= 128 && $arr[0] <= 2048 && $arr[1] <= 2048 )
{
// valid image
}
else
{
// error
}

注意:您应该使用内置的 pathinfo 函数来获取扩展名:pathinfo( $name, PATHINFO_EXTENSION )

关于php - 用户可以提交带有照片的数据。但是我这里无法查看图片内容。如何使用mime查看这里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28372943/

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