如何回显公用文件夹之外的图像 [英] How to echo image that is outside of the public folder

查看:73
本文介绍了如何回显公用文件夹之外的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个项目中,我将管理员提交的文件上传到公用文件夹之外的文件夹中.

In this project, I am uploading admin submitted files to a folder which is outside of the public folder.

/web/ (the public folder)
/upload/ (uploading image to this which is at the same level as the public folder)

虽然我现在可以使用绝对URL(/www/userid/upload/)来赞美我,但我无法使用相对或绝对URL来回显相同的图像.

Now allthough I am able to uplaod using the absolute url (/www/userid/upload/), I am unable to echo the same image using either relative or absolute url.

我已经尝试了<img src="/www/userid/upload/photo.jpg" /><img src="../upload/photo.jpg" />,但是没有一个工作.有什么提示吗?

I have tried <img src="/www/userid/upload/photo.jpg" /> as well as <img src="../upload/photo.jpg" /> but none is working. Any hints ?

推荐答案

direct路径不起作用,因为您无法从根文件夹之外获取内容.来自服务器目录路径的php脚本,并使用header

direct path won't work because you can't get content from outside of root folder.. you can do it another way, Read image file in php script from server dir path and serve file using header

脚本file.php

<?php
  $mime_type = mime_content_type("/image_path/{$_GET['file']}");
  header('Content-Type: '.$mime_type);

  readfile("/image_path/{$_GET['file']}");
?>


<img src="file.php?file=photo.jpg" />

这篇关于如何回显公用文件夹之外的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆