<?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 )
。