0

I have an HTML page that has the content shown below.

I want to display the image in the browser using a PHP script file titled "load_image.php" that loads the image using the PHP script and passing the image to the html page for display in the browser.

What will be the best PHP sctipt to do that? The image, image.gif, is located in the same directory as the html page and the PHP script.

I included a PHP working script that I am currently using, however it has some limitations that I want to avoid with a different script.

There is a reason why I use a PHP script and not a simple link in the HTML page to load the image.

Thanks, Menachem Blasberg

HTML Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>

<img src="http://www.inoxel.com/load_image.php" >

</body>

</html>

The image is my_image.gif

Current "load_image.php" PHP script:

<?php 

$my_image = "http://www.example.com/my_image.gif"; // Set image Full Path

readfile($my_image);

?>
Bruce
  • 1,647
  • 4
  • 20
  • 22
Menachem
  • 265
  • 1
  • 4
  • 17

4 Answers4

1
/* load_image.php */
<?php 

$my_image = "http://www.example.com/my_image.gif"; 

?>
/* Your HTML FILE */
<?php include ('load_image.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>

<img src="<?php echo $my_image ?>" >

</body>

</html>
Muhammad Atif
  • 1,050
  • 1
  • 9
  • 21
1
<?php

$path = 'http://www.inoxel.com/';
$image = 'load_image.php';

in Image

<img src="<?php echo $path.$image ?>" >
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

Modify your code to

<body>
<?php 
   echo "<img src='$my_image' >";
?>
</body>
Bruce
  • 1,647
  • 4
  • 20
  • 22
  • I tried it and it does not work. Note that I call the php file from my HTML page. It does work with my current implementation however I want to try a different method. – Menachem Jul 10 '15 at 16:14
0
<?php
$file = "https://example.com/March.jpg";
$contents =  file_get_contents($file);
$expires = 14 * 60*60*24;
header("Content-Type: image/jpg");
header('Content-disposition: attachment; filename="March.jpg"'); //Use for force to download
header("Content-Length: " . strlen($contents));
header("Cache-Control: public", true);
header("Pragma: public", true);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT', true);
echo $contents; //Image load
?>
CodAIK
  • 715
  • 7
  • 7