0

Below are codes that I use to encode the file in base64_encode, Can I encode file base64_encode that expires..? Means the output file from base64 can viewed in a certain time and then expires.

$fileurl = "./$viewmgfoto";///url of my file from database

$imageData = base64_encode(file_get_contents($fileurl));
$finfo = new finfo();

$fileinfo = $finfo->file($fileurl, FILEINFO_MIME);
$src = 'data: '.$fileinfo.';base64,'.$imageData;
$src= str_replace(" ","",$src);

echo $src 
jps
  • 20,041
  • 15
  • 75
  • 79
  • 5
    There is nothing to make a string (base64 encoded or not) just to expire, you will need to have some form of mechanism to add an expiry date to the content and check it when someone tries to use it. – Nigel Ren Oct 16 '22 at 13:42
  • Thank you @NigelRen Let me try another way. – Joman Manu Oct 16 '22 at 13:49
  • Base64 is just encoding, not encryption. Everyone can decode base64 encoded content. – jps Oct 16 '22 at 13:49
  • if this thing you wanted is for anything related to sensitive information, i'd advise against using `base64`. please use proper encryption algorithm. – Bagus Tesa Oct 16 '22 at 14:08
  • No.! am using base64 to encode Pdf files, So i was asking to encode expire file to prevent client to save key copied on the browser from dev tools side of network response, then to save it so that can access it any time. But am going to do it in another way; **1.** first am going to divide it in multiple keys then encode to `json_encode` by using `substr` **2.** if first method failed, i will generate unique URL by using random key in to access file by using **pdf.js** @BagusTesa – Joman Manu Oct 17 '22 at 09:25
  • @JomanManu regarding option 1, security over obsecurity effectiveness is dubious at best. you can go option 2, but isn't pdf.js allow the pdf to be saved anyway? but hey, just try it see which one works. – Bagus Tesa Oct 17 '22 at 09:43

0 Answers0