首页 > 解决方案 > 如何临时从文件夹中复制图像,然后在 PHP 中将其删除?

问题描述

我在 NAS 上有一个包含多个图像的文件夹。我想在文件夹中制作图像的本地副本,显示图像然后删除它们,这样它们就不会接管服务器上的本地。

查看照片后如何删除照片?

我制作了这段代码,但它删除了以下图像,因此无法显示:

<?php
$file = '//Alcyons/it/PhotoShoot/Photos_Outil/A1111_0070_1.jpg';
$newfile = 'A1111_0070_1.jpg';

if (!copy($file, $newfile)) {
    echo "La copie $file du fichier a échoué...\n";
}

echo "</td><td valign=top align=center><img src=\"$newfile\" border=0 width=180px></a></td><td width=10></td>";


unlink($newfile);

?>

标签: phpimagecopy

解决方案


复制文件能解决什么问题?

如果立即删除它有什么意义?

根据您的代码结构,那个会更好:

<?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>

推荐阅读