[PHP]How to show images in PHP without using HTML[Mac]

Status
Not open for further replies.

Mac

New Member
Feb 9, 2011
111
2
Hello , today i will show you how to show images in PHP without using HTML like that :
PHP:
<?
echo "<img src='IMAGE LINK'></a>";
?>
That code is still using HTML .

Here's the code without HTML (Look at it and then i will explain it!).
PHP:
<?
$image = file_get_contents("IMAGE LINK");
echo $image;
?>
Okay ! You are going to create a variable which it's value will get content of the image using "file_get_contents()" function. In the brackets you are going to make quotes and write image's url or link (starting with http:// ( ) like that "file_get_contents("http://images.com/image.gif");"


Php code (OOP) for that : (NO EXPLAIN FOR THIS)
PHP:
<?
class Image {
   function show_image($string) {
      echo file_get_contents($string);
   }
}
$image = new Image;
$image->show_image("IMAGE LINK");
?>

Thanks , for questions comment/reply
 

Meap

Don't need glasses if you C#
Nov 7, 2010
1,045
296
Thanks For This
Most People Code In PHP Nowadays
So, I Think This Is A Good TUT :)
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Just an improved version, it checks if the file exists and now you can use it for multiple images through $_GET

PHP:
<?php
class Image
{
	function show_image( $string )
	{
		echo ( ( file_exists( $string ) == true ) ? file_get_contents( $string) : 'Image does not exist!' );
	}
}
$image = new Image;
$image->show_image( $_GET['img'] );
?>

Access code:
PHP:
<img src="image.php?img=http://site.com/images/image1.png">
 
Status
Not open for further replies.

Users who are viewing this thread

Top