mardi 2 janvier 2018

php script to display a random image pulling their urls from a text file

I have this script in a file (called random.php) which displays a random image from the folder where it resides:

<?php 
$pics = glob('*.jpg', GLOB_NOSORT); 
$pic = $pics[array_rand($pics)]; 
header("Content-type: image/jpeg"); 
header("Content-Disposition: filename=\"" . basename($pic) . "\""); 
readfile($pic); 
?>

I am calling it as follows:

<img class="random" src="http://ift.tt/2Cxj9oa" />

It works properly.

I want instead to make it to display random pictures by pulling their urls from a text file full with lines, each line being an image url. How to do this?




Aucun commentaire:

Enregistrer un commentaire