• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI3 Encrypt/Decrypt Images

#3
(09-11-2019, 02:41 AM)InsiteFX Wrote: Read this article.

Encode Decode image using PHP
Thank you for your response.

I have disable the encrypt/decrypt portion of my code leaving just the base64_encode/decode portions and am still getting the above stated response. Here is the pieces I am using:

# open file to read it
$fhr = fopen($path_file, 'r+b');

# read entire file contents
$file_as_text = fread($fhr, filesize($path_file));
$type = pathinfo($path_file, PATHINFO_EXTENSION);

# encode
$file_as_text = 'data:image/' . $type . ';base64,' . base64_encode($file_as_text);

# open for writing
$fhw = fopen($path_file, 'w+b');

# write the file
fwrite($fhw, $file_as_txt);

#On decode
$cipher_txt = fread($fh, filesize($path_file));

# decode
$arr_data = explode(',', $cipher_txt);
$plain_txt = base64_decode($arr_data[1]);

# display
$image_resource = imagecreatefromstring($plain_txt);

if( $image_resource !== False )
{
        header("Content-type: image/jpeg");
        header("Content-length: " . (string)(filesize($path_file)));
        imagejpeg($image_resource);
}

Again, Thanks for looking. Second brain is always useful.
Reply


Messages In This Thread
CI3 Encrypt/Decrypt Images - by nuke - 09-10-2019, 06:34 PM
RE: CI3 Encrypt/Decrypt Images - by InsiteFX - 09-11-2019, 02:41 AM
RE: CI3 Encrypt/Decrypt Images - by nuke - 09-11-2019, 11:20 AM
RE: CI3 Encrypt/Decrypt Images - by InsiteFX - 09-11-2019, 05:54 PM
RE: CI3 Encrypt/Decrypt Images - by nuke - 09-12-2019, 03:36 AM
RE: CI3 Encrypt/Decrypt Images - by InsiteFX - 09-12-2019, 08:08 AM
RE: CI3 Encrypt/Decrypt Images - by nuke - 09-12-2019, 08:15 AM
RE: CI3 Encrypt/Decrypt Images - by InsiteFX - 09-12-2019, 11:10 AM
RE: CI3 Encrypt/Decrypt Images - by nuke - 09-12-2019, 04:00 PM
RE: CI3 Encrypt/Decrypt Images - by nuke - 09-16-2019, 07:03 AM
RE: CI3 Encrypt/Decrypt Images - by InsiteFX - 09-16-2019, 08:21 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.