[英]convert base64 image to jpg then upload to server not working
I am new to base64 and I have never needed to convert it so I am not sure what is going on here. 我是base64的新手,我从不需要转换它,所以我不确定这里发生了什么。 I have my base64 string in
$socialmedia_image
. 我在
$socialmedia_image
有我的base64字符串。 I create a random file name with rand
. 我用
rand
创建一个随机文件名。 I plug it into the function which I got off stack and....nothing. 我将其插入到我离开堆栈的函数中,..什么都没有。 It does not convert or transfer over with
move_uploaded_file
and I have no idea who to check for an error. 它不会通过
move_uploaded_file
转换或转移,而且我也不知道该由谁来检查错误。
Can someone tell me what I am doing wrong? 有人可以告诉我我在做什么错吗?
///// base64 string /////
$socialmedia_image = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg.....";
$rand = rand(000000000000000,999999999999999);
$output_file = $rand.".jpg";
$socialmedia_image = base64_to_jpeg( $socialmedia_image, $output_file );
function base64_to_jpeg($base64_string, $output_file) {
$ifp = fopen( $output_file, 'w' );
$data = explode( ',', $base64_string );
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
fclose( $ifp );
return $output_file;
}
move_uploaded_file($socialmedia_image, "../tickets/attachments/".$output_file);
那个怎么样?
file_put_contents($output_file, $data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.