gpt4 book ai didi

php - 在 php 中上传图片 base64 时出现 2174 错误

转载 作者:行者123 更新时间:2023-11-29 07:53:28 25 4
gpt4 key购买 nike

您好,请使用以下代码

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');

最佳答案

file_put_contents的返回值is not an error code :

This function returns the number of bytes that were written to the file, or FALSE on failure.

因此您的代码似乎没有任何问题。

关于php - 在 php 中上传图片 base64 时出现 2174 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25789992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com