Php 使用任何扩展名显示图像文件
我正在寻找一种方法,能够显示图像文件,而不知道扩展名。 我找到了一个在不知道的情况下查找文件的解决方案;s分机,现在我需要分机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
$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){
//我们至少有一场比赛,让我们用第一场
回声“”;
}