简体   繁体   中英

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. Below is my json request and php code of api.

PHP Code

<?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

  {
    "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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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