gpt4 book ai didi

php - 使用php从文件夹中的图像获取图像尺寸

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

我有一个问题。我需要使用 PHP 从文件夹中的图像中获取图像尺寸。我知道这可能是使用 PHP 函数 getimagesize 执行此操作的最佳方法,但我不知道在哪里将这段代码放入我的脚本中以便保存到数据库。你能帮我一下吗?这是我的 PHP 脚本:

<?php      

$server = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$dbname = 'dbname';

$connect = mysql_connect($server,$dbuser,$dbpass);
mysql_select_db($dbname,$connect);

$path = "gb-bilder-pics/augen/";
$files = array_map('mysql_real_escape_string',array_filter(glob("{$path}*.*"),'is_file'));
if(empty($files)){
echo "There were no matching files to insert into the database.";
}else{
$insertValues = array();
foreach($files as $file)
{
$insertValues[] = "('Titel', 'augen', '{$file}', '{$width????}', '{$height????}')";
}$query = "INSERT INTO `gbpics` (`gbpictitel`, `gbpiccat`, `gbpicurl`, `gbpicwidth`, `gbpicheight`) VALUES " . implode(', ', $insertValues);
if(!mysql_query($query)){
echo "There was a problem inserting the data.";
trigger_error("Query failed: $query<br />Error: " . mysql_error());
} else {
echo "The data was inserted successfully.";
}
}?>

最佳答案

(PHP 4, PHP 5, PHP 7) getimagesize — Get the size of an image

只需使用getimagesize并传递文件名。它将返回尺寸以及文件类型和高度/宽度文本字符串。

我建议在您计算机上的图像上尝试此功能,然后看看该方法的行为方式。我相信您将能够弄清楚如何从结果中提取宽度和高度。

如果您之后仍然需要帮助在您自己的代码中实现它,请不要害怕询问。

Source

关于php - 使用php从文件夹中的图像获取图像尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42970733/

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