Jump to content

Recommended Posts

Separate the path into parts and take the bits you need i.e

 

<?php
$path = '/var/www/html/mywebsite/images/foobar.jpg';
$parts = explode('/', $path);
$filename = $parts[count($parts)-1];
?>
<img src="/images/<?php echo $filename; ?>" />

Link to comment
https://forums.phpfreaks.com/topic/247646-image-path/#findComment-1271716
Share on other sites

Images should be accessible via the document root for the domain i.e http://www.xyz.com/images/test.jpg Not stored on some random part of your hard disk on a windows pc. You should be running a webserver like Apache or IIS do define the document root for your website. To get an image to display that it outside of the document root you would either have to copy it into the doc root folder i.e images/ or, as long as it has sufficient permissions use php to display it using the following:

 

<?php
if($image = @fopen('d:\\images\\sani.gif', 'rb')) {
header('Content-Type: image/gif');
fpassthru($image);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/247646-image-path/#findComment-1271976
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.