Hi,
I am trying to show an image on a Wordpress post from a folder on the server. The images in the folder are put into an array using scandal and the . and … are ignored. The folder that the image comes from is selected using GET and is put into the url at the end of the address along with the image number. This is so the latest image (which is timestamped on the filename can be chosen using the array number.
Loading up the URL directly using "http://www.weburl.com/wp-content/.../getlatestimage.php?image=pap&num=1 will load up the image directly however if I try and put it in as img src or via an image block will not load the photo into the page. I believe that this is because the code echos an in the php but I do not know how to load it into a constructed webpage any other way.
Here is the code I have written:
<?php
$imagepath = htmlspecialchars($_GET["image"]);
$imagenum = htmlspecialchars($_GET["num"]);
define('LOCALHOST', 'localhost' === $_SERVER['SERVER_NAME'] );
If(LOCALHOST){
define('PATH_IMAGES', 'this_path');
}else{
define('PATH_IMAGES', '../../../Images/');
}
?>
-
<?php
$arrnum = $GLOBALS[imagenum] - 1;
echo $arrnum;
$dirname = PATH_IMAGES . $GLOBALS[imagepath]."/";
$images = scandir($dirname);
rsort($images);
$ignore = Array(".", "..");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
//echo "
- "; header('Content-type: image/jpeg'); //echo file_get_contents($dirname$images[$arrnum]); echo "<img src='$dirname$images[$arrnum]'width='1600'";
}
}
?>
Any and all help will be greatly appreciated