Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用任何扩展名显示图像文件_Php_Html - Fatal编程技术网

Php 使用任何扩展名显示图像文件

Php 使用任何扩展名显示图像文件,php,html,Php,Html,我正在寻找一种方法,能够显示图像文件,而不知道扩展名。 我找到了一个在不知道的情况下查找文件的解决方案;s分机,现在我需要分机 $result = glob('uploads/logo_'.$row['id'].'.*'); if(is_array($result)) { echo '<p><img src="uploads/logo_'.$row['id'].'.???" height="75"></p>'; } $result=glob('uploa

我正在寻找一种方法,能够显示图像文件,而不知道扩展名。 我找到了一个在不知道的情况下查找文件的解决方案;s分机,现在我需要分机

$result = glob('uploads/logo_'.$row['id'].'.*');
if(is_array($result))
{
  echo '<p><img src="uploads/logo_'.$row['id'].'.???" height="75"></p>';
}
$result=glob('uploads/logo.'.$row['id']....*);
if(是_数组($result))
{
回声“

”; }
好吧,当您使用glob时,您已经拥有文件的完整路径,包括文件扩展名

$result = glob('uploads/logo_'.$row['id'].'.*');
if(is_array($result))
{
  echo '<p><img src="uploads/logo_'.$row['id'].'.???" height="75"></p>';
}
我在这里动态编写了一些代码(我还没有测试):

要显示所有匹配的图像,请执行以下操作:

$result = glob('uploads/logo_'.$row['id'].'.*');
if(!empty($result))
{
    foreach ($result as $file) {
        if (@is_array(getimagesize($file))) {
            $relativePath = end(explode('/', $file));
            echo '<p><img src="uploads/' . $relativePath . '" height="75"></p>';
        }
    }
}
$result=glob('uploads/logo.'.$row['id']....*);
如果(!空($result))
{
foreach($result作为$file){
if(@is_数组(getimagesize($file))){
$relativePath=end(分解('/',$file));
回声“

”; } } }
--

要显示第一个匹配的图像,请执行以下操作:

$result = glob('uploads/logo_'.$row['id'].'.*');
if(!empty($result))
{
    $file = current($result);
    if (@is_array(getimagesize($file))) {
        $relativePath = end(explode('/', $file));
        echo '<p><img src="uploads/' . $relativePath . '" height="75"></p>';
    }
}
$result=glob('uploads/logo.'.$row['id']....*);
如果(!空($result))
{
$file=当前($result);
if(@is_数组(getimagesize($file))){
$relativePath=end(分解('/',$file));
回声“

”; } }

请考虑我不排除任何图像文件。如果您确定根本没有非图像文件,则可以跳过

@is_数组(getimagesize($file))
条件

好的,当您使用glob时,您已经拥有文件的完整路径,包括文件扩展名

$result = glob('uploads/logo_'.$row['id'].'.*');
if(is_array($result))
{
  echo '<p><img src="uploads/logo_'.$row['id'].'.???" height="75"></p>';
}
我在这里动态编写了一些代码(我还没有测试):

要显示所有匹配的图像,请执行以下操作:

$result = glob('uploads/logo_'.$row['id'].'.*');
if(!empty($result))
{
    foreach ($result as $file) {
        if (@is_array(getimagesize($file))) {
            $relativePath = end(explode('/', $file));
            echo '<p><img src="uploads/' . $relativePath . '" height="75"></p>';
        }
    }
}
$result=glob('uploads/logo.'.$row['id']....*);
如果(!空($result))
{
foreach($result作为$file){
if(@is_数组(getimagesize($file))){
$relativePath=end(分解('/',$file));
回声“

”; } } }
--

要显示第一个匹配的图像,请执行以下操作:

$result = glob('uploads/logo_'.$row['id'].'.*');
if(!empty($result))
{
    $file = current($result);
    if (@is_array(getimagesize($file))) {
        $relativePath = end(explode('/', $file));
        echo '<p><img src="uploads/' . $relativePath . '" height="75"></p>';
    }
}
$result=glob('uploads/logo.'.$row['id']....*);
如果(!空($result))
{
$file=当前($result);
if(@is_数组(getimagesize($file))){
$relativePath=end(分解('/',$file));
回声“

”; } }

请考虑我不排除任何图像文件。如果您确定根本没有非图像文件,那么可以跳过

@is_数组(getimagesize($file))
条件

您基本上已经编写了解决方案
glob
实际上返回匹配的文件名

$result = glob('uploads/logo_'.$row['id'].'.*');

// glob returns an empty array if no matching files are found,
// so we need to check if the result is empty or not.
if (is_array($result) && count($result) > 0) {

    // We got at least one match, let's use the first one
    echo '<p><img src="'. $result[0] .'" height="75"></p>';
}
$result=glob('uploads/logo.'.$row['id']....*);
//如果找不到匹配的文件,glob将返回空数组,
//所以我们需要检查结果是否为空。
if(is_数组($result)&&count($result)>0){
//我们至少有一场比赛,让我们用第一场
回声“

”; }
您基本上已经编写了解决方案
glob
实际上返回匹配的文件名

$result = glob('uploads/logo_'.$row['id'].'.*');

// glob returns an empty array if no matching files are found,
// so we need to check if the result is empty or not.
if (is_array($result) && count($result) > 0) {

    // We got at least one match, let's use the first one
    echo '<p><img src="'. $result[0] .'" height="75"></p>';
}
$result=glob('uploads/logo.'.$row['id']....*);
//如果找不到匹配的文件,glob将返回空数组,
//所以我们需要检查结果是否为空。
if(is_数组($result)&&count($result)>0){
//我们至少有一场比赛,让我们用第一场
回声“

”; }