0

I am trying to publish an image that generated by my steganography web. So here is the current flow.

  1. User choose an image for the steganography
  2. User input their message
  3. Web will generate new image that already have that message inside <img> tag

How can I upload this new generated image to my localhost/images/ ?

Expected behavior:

After the image is generated user will press publish button, it will create a post request and also upload the generated image to desired location.

<img src="" id="final_image" class="img-thumbnail">

I have the generated image here. and currently have to move manually by, right click > save as > desired destination.

Striezel
  • 3,693
  • 7
  • 23
  • 37

1 Answers1

0

First get the image and convert to base64 using js or jQuery and save base64 image as file using php like this

$data = 'data:image/png;base64,AAAFBfj42Pj4';

list($type, $data) = explode(';', $data);
list(, $data)      = explode(',', $data);
$data = base64_decode($data);

file_put_contents('/tmp/image.png', $data);
piet.t
  • 11,718
  • 21
  • 43
  • 52
Shazvan Hanif
  • 361
  • 3
  • 20
  • 1
    is in this solution i have to upload the original file and then rewrite it with the one that i generated? , base on this http://php.net/manual/en/function.file-put-contents.php – M Umar Ramadhana Jun 12 '18 at 11:14
  • you can check this(https://stackoverflow.com/questions/19146954/replace-file-in-php) – Shazvan Hanif Jun 12 '18 at 11:19
  • 1
    it works thanks!!!, so i upload the original image first, and then rewrite it with the base64 string, i don't get it at first. but thanks – M Umar Ramadhana Jun 12 '18 at 12:12