i had encoded image binary ($binaryimage) in string. want save in file in server.here code, got result: fwrite() expects parameter 1 resource, boolean given... . code wrong?
$binary=base64_decode($binaryimage); header('content-type: bitmap; charset=utf-8'); $file = fopen('../uploadedimages/'.$filename, 'wb'); // create file fwrite($file, $binary); fclose($file); (edit) tried :
if($file===false){ echo "failed file"; } // create file if(fwrite($file, $binary)===false){ echo "failed write"; } get message:
fopen(../uploadedimages/fb_img_1437004428570.jpg): failed open stream: no such file or directory in <b>/home/u505221043/public_html/welcom/include/db_functions.php my php code in "include" directory. , "uploadedimage" 777 mode.
->include ->function.php ->uploadedimages
file() returns boolean when fails open file.
this several reasons such incorrect path or permissions.
i recommend adding guard clause, @ least debug issues:
$file = fopen('../uploadedimages/' . $filename, 'wb'); if ($file === false) { exit("failed file"); }
Comments
Post a Comment