Tuesday, June 25, 2013

download and save image into server base64 decode using php

 define('UPLOAD_DIR', 'C:\inetpub\wwwroot\PHP\images\Shareimage/');
 $imagePath=$_POST['img_val'];


       /* header("Content-Transfer-Encoding: binary");
        header("Content-Type: image/jpg");
        header("Content-Disposition: attachment; filename=custom-img.jpg");
        //start feeding with the file
readfile($imagePath);
*/



 
$imagePath = str_replace('data:image/jpeg;base64,', '', $imagePath);
$imagePath = str_replace(' ', '+', $imagePath);
$data = base64_decode($imagePath);
$file = UPLOAD_DIR  .'customshare.jpeg';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';

No comments:

Post a Comment