我怎样才能阻止直接访问图像目录但允许PHP来显示它们?图像、直接、目录、PHP

由网友(半呆半萌半幼稚)分享简介:我用用下面的code .htaccess文件:I'm using a .htaccess file with the following code:Order deny, allowDeny from allAllow from localhost但是,当我显示我只是把一个链接到图像中的标记的图像,但图像没有显...

我用用下面的code .htaccess文件:

I'm using a .htaccess file with the following code:

Order deny, allow
Deny from all
Allow from localhost

但是,当我显示我只是把一个链接到图像中的标记的图像,但图像没有显示出来。

But when I display the images I'm just putting a link to the image in an tag, but the images are not showing up.

我怎样才能显示图像,但不允许直接访问它?有没有一种办法,我刚才复制的文件的原始字节并显示出来?

How can I display the image but disallow direct access to it? Is there a way for me to just copy the raw bytes of the file and display them?

推荐答案

一定要保存的 embedded.png 的在同一个文件夹如本例源。

Be sure to save embedded.png in same folder as this example source.

<?php
function data_uri($file, $mime) 
{  
  $contents = file_get_contents($file);
  $base64   = base64_encode($contents); 
  return ('data:' . $mime . ';base64,' . $base64);
}
?>

<html>
    <h1>Embedded Image:-</h1>
    <img src="<?php echo data_uri('embedded.png','image/png'); ?>" alt="Embedded image" />
</html>
阅读全文

相关推荐

最新文章