Reputation: 120
I have a PNG image located outside of public_html. I want to put that picture in a <img>
tag. Does anyone know how to do that with php?
Upvotes: 0
Views: 1655
Reputation:
You could have an intermediary that outputs the image, sending the correct headers:
<?php
$path = '/some/sanizied/path.png';
header( 'Content-Type: image/png' );
// other headers like Length are nice, too.
readfile( $path );
There are also X-Sendfile and X-Accel-Redirect headers that can instruct your web server to deliver another file. This removes some PHP overhead.
Upvotes: 1
Reputation: 10892
i think your really asking just a plain html question, tho I'd need to see your actual code to give you a accurate answer.
If the png image file is located in another file/directory location, your code might looking something like this.
<img src='../file2/happy.png' alt='happy' />
The above will go up a directory level, then go into the folder 'file2' and point to the happy.png image file there.
Nothing to do with php when it comes down to specifying directory location of an image file, unless your trying to dynamically create the location which changes regularly.
Upvotes: 0