使用 php 未使用 base64 将大图像上传到服务器
Large image is not uploading on server in base64 using php
我制作了一个Api,其中我必须上传base64格式的图片,
但是当我尝试以 base64 格式上传大图像(820 KB)时,它显示
500 内部服务器错误 & 如果我尝试上传小图像 (16 KB) 然后它
已上传 successfully.I 也已检查服务器上传大小限制
64mb.I 我不明白为什么它不上传大型 base64 图像字符串。
下面是我的 json 请求和 api 的 php 代码。
PHP代码
<?php
$jsonreq = $app->request->getBody();
$encodedata = json_decode($jsonreq, true);
$userid = !empty($encodedata['userid']) ? $encodedata['userid'] : '';
$goal = !empty($encodedata['goal']) ? $encodedata['goal'] : '';
$title = !empty($encodedata['title']) ? addslashes($encodedata['title']) : '';
$category = !empty($encodedata['category']) ? $encodedata['category'] : '';
$story = !empty($encodedata['story']) ? $encodedata['story'] : '';
$image = !empty($encodedata['photo']) ? $encodedata['photo'] : '';
$db = getDB();
$sql = "SELECT * FROM users where id='" . $userid . "'";
$stmt = $db->query($sql);
$obj = new stdClass();
if ($stmt->rowCount() > 0) {
if ($image != "" || $image != NULL) {
$users = $stmt->fetch(PDO::FETCH_OBJ);
$img = str_replace('data:image/png;base64,', '', $image);
$img = str_replace(' ', '+', $img);
$fileName = uploadBase64Image($userid, $img, uploadFundraiserImage);
$imagepath = uploadFundraiserImage . $fileName;
$imagepath = str_replace('../', '', $imagepath);
} else {
$imagepath = '';
}
?>
下面是我的json请求
{
"goal":22,
"title":"test new2",
"story":"test new2",
"category":"health",
"userid":"46",
"photo":"here we paste base64 image string"
}
在这里,如果我们采用大图像,例如我的 imge 大小是 800 kb,对于下面的 base64 字符串,那么它显示 500 内部服务器错误,因为下面 string.I 无法粘贴 bas64 字符串,因为它很长但如果我们拍摄 800kb 或更大的图像,则会显示以下错误。
500 Internal Server Error
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
我刚刚在我的 domain.After 上关闭了 ModSec,它工作正常它是一个服务器配置错误,代码中没有错误。
我制作了一个Api,其中我必须上传base64格式的图片, 但是当我尝试以 base64 格式上传大图像(820 KB)时,它显示 500 内部服务器错误 & 如果我尝试上传小图像 (16 KB) 然后它 已上传 successfully.I 也已检查服务器上传大小限制 64mb.I 我不明白为什么它不上传大型 base64 图像字符串。 下面是我的 json 请求和 api 的 php 代码。
PHP代码
<?php
$jsonreq = $app->request->getBody();
$encodedata = json_decode($jsonreq, true);
$userid = !empty($encodedata['userid']) ? $encodedata['userid'] : '';
$goal = !empty($encodedata['goal']) ? $encodedata['goal'] : '';
$title = !empty($encodedata['title']) ? addslashes($encodedata['title']) : '';
$category = !empty($encodedata['category']) ? $encodedata['category'] : '';
$story = !empty($encodedata['story']) ? $encodedata['story'] : '';
$image = !empty($encodedata['photo']) ? $encodedata['photo'] : '';
$db = getDB();
$sql = "SELECT * FROM users where id='" . $userid . "'";
$stmt = $db->query($sql);
$obj = new stdClass();
if ($stmt->rowCount() > 0) {
if ($image != "" || $image != NULL) {
$users = $stmt->fetch(PDO::FETCH_OBJ);
$img = str_replace('data:image/png;base64,', '', $image);
$img = str_replace(' ', '+', $img);
$fileName = uploadBase64Image($userid, $img, uploadFundraiserImage);
$imagepath = uploadFundraiserImage . $fileName;
$imagepath = str_replace('../', '', $imagepath);
} else {
$imagepath = '';
}
?>
下面是我的json请求
{
"goal":22,
"title":"test new2",
"story":"test new2",
"category":"health",
"userid":"46",
"photo":"here we paste base64 image string"
}
在这里,如果我们采用大图像,例如我的 imge 大小是 800 kb,对于下面的 base64 字符串,那么它显示 500 内部服务器错误,因为下面 string.I 无法粘贴 bas64 字符串,因为它很长但如果我们拍摄 800kb 或更大的图像,则会显示以下错误。
500 Internal Server Error
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
我刚刚在我的 domain.After 上关闭了 ModSec,它工作正常它是一个服务器配置错误,代码中没有错误。