Php 如何从目录中列出IMAG?
我正在尝试显示指定目录中的所有图像 以下代码列出了所有允许的文件名:Php 如何从目录中列出IMAG?,php,fileinfo,imagelist,Php,Fileinfo,Imagelist,我正在尝试显示指定目录中的所有图像 以下代码列出了所有允许的文件名: function getDirectoryList() { // create an array to hold directory list $results = array(); // create a handler for the directory $handler = opendir($this->currentDIR); // open directo
function getDirectoryList()
{
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($this->currentDIR);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// Make sure we get allowed images types
if ($this->allowedFileType($file,$this->allowedImageTypes) )
{
$results[] = $file;
}
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
(...)
$images = getDirectoryList();
foreach($images as $img) {
echo "<li>".$img."</li>";
}
函数getDirectoryList()
{
//创建一个数组来保存目录列表
$results=array();
//为目录创建一个处理程序
$handler=opendir($this->currentDIR);
//打开目录并浏览文件名
而($file=readdir($handler)){
//确保我们得到允许的图像类型
如果($this->allowedFileType($file,$this->allowedImageTypes))
{
$results[]=$file;
}
}
//整理:关闭处理程序
closedir($handler);
//完成了!
返回$results;
}
(...)
$images=getDirectoryList();
foreach($img形式的图像){
回声“mime\u content\u type
已被弃用,我应该使用istead。但我在这方面不是很成功
我是否必须使用/usr/share/misc/magic
获取文件信息?我不能使用GD库吗
我看过很多例子,但它们都很老,效果也不太好
感谢您的帮助。要获得图像的大小和mime类型 使用功能: 例如:
list($width, $height, $type, $attr) = getimagesize("img/myimg.jpg");
返回包含7个元素的数组
索引0和1分别包含图像的宽度和高度
索引2是指示图像类型的IMAGETYPE_XXX常量之一
使用give the size in bytes展开Haim Evgi的文章,使用检索数组中的维度和图像类型。然后,使用图像类型代码检索MIME:
list ($fileWidth, $fileHeight, $fileType) = getimagesize($filename);
$fileMimeType = image_type_to_mime_type($fileType);
谢谢这至少给了我MIME类型。但是我需要的是文件大小,而不是图像的高度/宽度。我只是希望可能有一个文件函数包含所有这些信息。