我拥有第一个PHP脚本,该脚本可让我在远程服务器上显示图像。这是可行的,我想做一个条件,以便当它在$ file变量中找不到图像时,它将在$ newfile变量中显示图像。
但是出现错误“警告:file_get_contents():C:\ wamp64 \ www ...中的文件名不能为空”
我的错误在哪里?
<!-- Old Script -->
<?php
$file = '//Alcyons/it/PhotoShoot/Photos_Outil/A1111_0070_1.jpg';
$type = pathinfo($file, PATHINFO_EXTENSION);
?>
</td>
<td valign=top align=center>
<img src="<?php echo "data:image/$type;base64,",
base64_encode(file_get_contents($file)) ?>" border=0 width="180"></a>
</td>
<td width=10></td>
<!-- New Script -->
<?php
$file = '//Alcyons/it/PhotoShoot/retail/Photos/SS20,FW1920/A1127G_00_1.jpg';
$newfile = '//Alcyons/it/PhotoShoot/retail/Photos/SS20,FW1920/A1119_4023_1.jpg';
$type = pathinfo($file, PATHINFO_EXTENSION);
?>
</td>
<td valign=top align=center>
<img src="<?php
if ($file = NULL)
{
echo "data:image/$type;base64,", base64_encode(file_get_contents($newfile));
}
else
{
echo "data:image/$type;base64,", base64_encode(file_get_contents($file));
}
?>" border=0 width="180"></a>
</td>
<td width=10></td>
错误就在这里:
if ($file = NULL)
您将$ file变量设置为“ null”,可能需要进行比较:
if ($file == NULL)