您可以使用以下代码
if($data['photo']!='')
{
define("UPLOAD_DIR", "admin/alumni_image/");
$photo = $data['photo'];// THIS IS YOUR BASE64 ENCODED STRING
$photo = str_replace('data:image/png;base64,', '', $photo);
$photo = str_replace(' ', '+', $photo);
$data = base64_decode($photo);
$time =microtime(true);
$micro_time=sprintf("%06d",($time - floor($time)) * 1000000);
$date=new DateTime( date('Y-m-d H:i:s.'.$micro_time,$time) );
$currentDatetime=$date->format("Y-m-d H:i:s.u");
$file = UPLOAD_DIR . md5($currentDatetime) . '.png';
$array=explode("/",$file);
$photoName=$array[2];
$success = file_put_contents($file, $data);
echo $success;
$query_photo = "update alumni set photo = '".$photoName."' where alumni_id = '".$insert_id."'";
$query_run= mysql_query($query_photo);
}
但是我得到错误2174.我增加了php配置文件的大小,如
ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '64M');
答案 0 :(得分:2)