Running Image Service from PHP

By | July 21, 2016

Scenario : Imagine that you want to run an image service and your clients will use these images in their static site developments. The moment you change these in the server it automatically reflect in the client designs.

This is a POC design and can be used in KIOSKS, Web designs etc.

Basically wherever you need the dynamic image you will use image src as a php destination.

<img src=”” />

Whenever the server receives the request it will serves the image whichever is assigned to that.



header("Content-type: text/xml");




If you wish to make it dynamic then store the image data in a mysql database.

Then select the image randomly or by sending query parameter so that you will get dynamic images.


Hereis the sample codes to get and display data from mysql database



$servername = “localhost”;

$username = “xxxxxxx”;

$password = “xxxx”;

$dbname = “haneee_2015”;


// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

die(“Connection failed: ” . $conn->connect_error);



$sql = “SELECT img_name FROM hanee_2015.tbl_banners WHERE active=1 AND img_name LIKE ‘%.jpg%’ LIMIT “.$_GET[“img”].”, 1;”;

$result = $conn->query($sql);



if ($result->num_rows > 0) {

// output data of each row

while($row = $result->fetch_assoc()) {

$txt=”” . $row[“img_name”]. ” <br>”;



} else {







header(“Content-type: text/xml”);






This is a sample script.

You can call this image service using following test code




<img src="" />





Using this you can develop further.

For any help please leave your question.