Display image using absolute path - php

I am using uploadify to upload img to server at the time of upload i saved absolute path to the data base its like:
/var/www/html/workbench/photogallery/uploads/logo2.jpg
now I want to display the same in browser the following method does not work
<div id="photos">
<h3>Photo title</h3>
<P class="like">Like </P>
<p class="date">date </p>
<p class="pclear" />
<div id="image">
<img src="<?php echo $result_set['path']; ?>" />
</div>
<p class="about">about image goes here</p>
</div>
above code doesn't work. when I edit the path manually to uploads/logo2.jpg it works perfectly
how can I resolve this problem?

You need to use an url, not a path.
This:
/var/www/html/workbench/photogallery/uploads/logo2.jpg
is a physical path, the address on that server where the image is found. You need to use an url available for your visitors. I guess that you have a name mapped to that server (something like localhost or www.example.com).
From the structure I guess that your url would be something like
http://www.example.com/photogallery/uploads/logo2.jpg
where www.example.com is the base url you are using to get to that application

Try this:
<img src="/photogallery/uploads/<?php echo basename($result_set['path']) ?>" />

Try this it works for me and keeps the location of the images hidden from the browser.
<img src='fake.php' style='max-width:90px;'/>
Create a file called fake.php as follows
<?php
$thePic = "/var/www/html/workbench/photogallery/uploads/logo2.jpg";
$image = imagecreatefromjpeg($thePic);
// Output image and free up the memory
header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
?>
You can adjust the code in the fake.php file to retrieve the location of $thePic from posted data or database, etc.

Related

Problem in access image file from outside of script folder

Problem: Hard to synchronise image between 2 folder
My project has 2 image folder:
Home/user/public_html/image
Home/user/m.fruit.com/image
public_html serves the main page for desktop version
m.fruit.com serves the mobile page
Both version serves the same images.
When I have new fruit image, I need to put it into both folder. This becomes double work...
my way of accessing image for desktop version is: (index.php in public_html folder)
<img id="image" src="image/<?php echo $image; ?>.jpg">
my way of accessing image for mobile version is: (index.php in m.fruit.com folder)
<img id="image" src="image/<?php echo $image; ?>.jpg">
For mobile version, I did try to access image in public_html so that I don't need 2 image folder. But it seems like not possible:
<img id="image" src="public_html/image/<?php echo $image; ?>.jpg">
Is there any way to use only 1 image folder to serves these 2 version of website instead of 2 in this case?
Other better solution also welcomed.
First, you can set base URL: like
define('BASE_URL', 'http://example.com/');
then set image src:
<img src="<?php echo BASE_URL ?>image/imagename.jpg ">
or create a helper function:
PHP CODE
function asset(path){
return BASE_URL . path;
}
HTML CODE:
<img src="<?php echo asset('image/imagename.jpg'); ?> ">
This will work on both sides.
Try to change the image url scheme with this
<?php echo "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>
define base_url();
define('base_url', 'http://Home/user');
and then call this base url where you want show image.
<img id="image" src="image/<?php echo base_url('/public_html/').$image; ?>">

<img src= url> Not showing image on index.php

I used following code on index.php and it is 100% working on localhost, but not appear image on live server "www.chitthu.co".
<div class="block">
<img src="/img/step-1.png" style="width:20%; height:20%; margin:5px;">
<h3>Join Chitthu</h3>
<p>
Signing up takes two
minutes <br>to get a Chitthu account.
</p>
</div>
step-1 to Step-1.
It seems that your server is case sensitive, which means S and s is very different.
Open your directory :
www.chitthu.co/img/
You don't have this image:
www.chitthu.co/img/step-1.png
You have:
www.chitthu.co/img/Step-1.png
Your directory:
Try this Step-1 http://www.chitthu.co/img/Step-1.png
<img src="http://www.chitthu.co/img/Step-1.png" alt="Step-1"/>

Wordpress logo image in header.php

I'm trying to create a custom theme in Wordpress, and currently I'm working on my header.php file. However, I'm unable to display my logo image. Here's the code for the same:
<body>
<div class = "container">
<div class = "five columns">
<img src = "<?php bloginfo('template_url'); ?>/img/sem.jpg" title = "<?php bloginfo('title'); ?>">
</div>
</div>
</body>
The sem.jpg image is stored inside the img folder inside my root project directory. However, the logo doesn't seem to be displayed on my webpage. I have also tried using images of other formats, but none of them seems to work. I have also called the get_header() function inside my index.php.
What seems to be wrong in my code?
The reason seems a permissions problem.
You can set permission 777 to the logo image via command line, typyng:
chmod 777 /path_to_your_file
or set using right click on the logo file, and change properties.
You can't view your image because you have got set wrong permissions on your image. Open your FTP client, connect to your site and find your image, right click it and chosse Change file permissions and change them to 644.
File permissions should look like this:
http://s12.postimg.org/rxb25ziy5/Untitled.png
Try This.
<body <?php body_class(); ?>>
<div class = "container">
<div class = "five columns">
<img src="<?php echo get_template_directory_uri(); ?>/img/sem.jpg" alt="<?php bloginfo('title'); ?" />
</div>
</div>
</body>
Enjoy..!!
user this wordpress plugin
it will help yo upload logo using wordpress admin and you can change any time with edit header.php file.
Use below function to print logo
echo theme_logo();

How to Autoload & Display Images in View (Codeigniter)

I am a newbie to codeigniter framework. I have created a PHP slider that load images automatically, it works fine in PHP only. Now I used codeigniter, the PHP code does not work well, just can't read the images in a folder.
PHP code:
<div class="slider-wrapper">
<div id="slider" class="phpSlider">
<?php $dir_handle='./slider/images/';
foreach(array_diff(scandir($dir_handle), array( '.', '..')) as $file) {
echo '<img src="./slider/images/'.$file. '" />';
}
?>
</div>
</div>
the code works fine without codeigniter. It reads all images in a specific folder "images" under "slider" folder. And the code when run on browser looks like below:
<div class="slider-wrapper">
<div id="slider" class="phpSlider">
<img src="slider/images/banner1.jpg">
<img src="slider/images/banner2.jpg">
<img src="slider/images/banner3.jpg">
<img src="slider/images/banner4.jpg">
<img src="slider/images/banner5.jpg">
</div>
</div>
It is looking like a path issue. Please use base_url() with img src. where base_url() is your project directory url where your index.php file exist.
echo '<img src="'.base_url().'path/to/images/'.$file. '" />';
Changing the folder path to absolute URL solved the problem.

What is wrong with my PHP code?

I have been seriously been looking at this forever! I'm going out of my mind And can't figure out why my images are not displaying in my custom made footer.
I have firefox with firebug and it is simply saying that the url is failing to load. so I copy and pasted a url to an image that is currently working and is being shown via the background property in CSS just fine. (thats the top one that says dakota jones). copy and pasting the exact img src proves it still not to work.
my folder is images. My functions.php is right outside. the hierarchy is correct. what the heck?? The testing text in the p tags work just fine. uhuhuhu
Somebody help me! I'm using wp and genesis theme.
add_action('genesis_before_footer', 'include_sponsors');
function include_sponsors() { ?>
<div class="sponsors">
<p>This is testing text</p>
<img src="images/dakotajonesheader3.jpg" alt="Smiley face" height="42" width="42" />
<img src="images/tfobw.png" />
<img src="images/basskingbw.png" />
<img src="images/bighawgbw.png" />
<img src="images/kbw.png" />
<img src="images/mccoybw.png" />
<img src="images/nfcbwpng" />
<img src="images/rayjusbw.png" />
<img src="images/rrbw.png" />
</div>
<?php }
Use WordPress' inbuilt function:
<?php
bloginfo('template_directory'); ?>/images/dakotajonesheader3.jpg
?>
.. which will reference /wp-content/themes/your-theme/images/dakotajonesheader3.jpg
Wordpress dynamically rewrites URLs, so the URL you use to access a page is not the same as the path to the scripts that are running on the server. So you might request your page with example.com/Home. But your images are not stored in example.com/Home/images, which is where you're telling your browser to look. They're stored in example.com/wordpress/wp-content/themes/your_theme/images. So you have to give the absolute path to the images to the browser in your <img> tags.
Carson is correct, and you can use absolute paths to your images. Alternatively, if you want to avoid using absolute paths, you can call your images using bloginfo('template_directory');
For example:
<img src="<?php bloginfo('template_directory'); ?>/images/dakotajonesheader3.jpg" alt="Smiley face" height="42" width="42" />

Categories