Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide image path from source code using PHP

Tags:

php

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?

like image 293
Mak Avatar asked May 12 '26 18:05

Mak


1 Answers

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.

like image 111
Venkata Krishna Avatar answered May 15 '26 07:05

Venkata Krishna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!