I want to hide image path from website. To do that first I did this:
<?php
// get image path
$path = 'images/profiles/uploads/' . $list['thumbnail'];
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
?>
But this is very slow, So I try to implement like this, but code is not working:
download.php:
function setImgDownload($imagePath) {
$image = imagecreatefromjpeg($imagePath);
header('Content-Type: image/jpeg');
imagejpeg($image);
}
mypage.php:
<?php include('download.php'); ?>
<img src="<?php setImgDownload('images/Chrysanthemum.jpg') ?>" width="300"/>
If I put function and call function at the same page it's working:
function setImgDownload($imagePath) {
$image = imagecreatefromjpeg($imagePath);
header('Content-Type: image/jpeg');
imagejpeg($image);
}
setImgDownload('images/Chrysanthemum.jpg');
How to keep function in separate page?
Try changing your mypage.php to
<?php
include('download.php');
echo "<img src='".setImgDownload('images/Chrysanthemum.jpg')."' width='300'/>"; // calling function inside php
?>
Here, instead creating the HTML element outside php, put it inside php using echo and just escape while calling the php function. This should give you what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With