简体   繁体   English

使用php在base64上的服务器上无法上传大图像

[英]Large image is not uploading on server in base64 using php

I have made a Api in which i have to upload the image of base64 format, but when i try to upload large image(820 KB) in base64 format it is showing 500 internal server error & if i tried to upload the small image(16 KB) then it is uploaded successfully.I have also check the server upload size limit it is 64mb.I am not getting why it is not uploading large base64 image string. 我已经制作了一个Api,我必须上传base64格式的图像,但当我尝试以base64格式上传大图像(820 KB)时,它显示500内部服务器错误,如果我试图上传小图像(16 KB)然后它上传成功。我还检查服务器上传大小限制它是64mb.I不知道为什么它没有上传大型base64图像字符串。 Below is my json request and php code of api. 下面是我的json请求和api的php代码。

PHP Code 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 = '';
            }

?>

Below is my json request 以下是我的json请求

  {
    "goal":22,
    "title":"test new2",
    "story":"test new2",
    "category":"health",
    "userid":"46",
    "photo":"here we paste base64 image string"  
    }

Here if we take large image for example my imge size is 800 kb for the below base64 string then it shows 500 internal server error for below string.I can't able to paste bas64 string because it quite long but if we take a image of 800kb or more than this than it shows the following error. 这里,如果我们采用大图像,例如我的imge大小是800 kb以下的base64字符串然后它显示500内部服务器错误下面的字符串。我无法粘贴bas64字符串因为它很长但是如果我们拍摄的图像800kb或更多比它显示以下错误。

500 Internal Server Error
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.

我刚刚在我的域上关闭了ModSec。之后,它的工作正常,服务器配置错误,代码中没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM