3

I have Data URI(image) and I am trying to save using php, my code is

$filename = 'test.png';
$fp = fopen("user_images/".$filename,"w");
fwrite($fp, base64_decode($_POST['strDataURI']));
fclose($fp);

It gives me corrupted image always, But i am getting right image when i use in Javascript

document.write('<img src="'+strDataURI+'"/>');
Dhwani
  • 7,484
  • 17
  • 78
  • 139
Nithin Dev
  • 421
  • 10
  • 29

1 Answers1

2

Given that I believe PHP now supports (>5.4.17 ) "proper" data URIs (i.e. without the double-slash necessary in older versions) I'd probably just try this:

fwrite($fp, file_get_contents($_POST['strDataURI']);

...seems to work okay in PHP 5.4.17 using a test script I just wrote using a data uri generated from this online tool.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
Matt Gibson
  • 37,886
  • 9
  • 99
  • 128