繁体   English   中英

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

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

我已经制作了一个Api,我必须上传base64格式的图像,但当我尝试以base64格式上传大图像(820 KB)时,它显示500内部服务器错误,如果我试图上传小图像(16 KB)然后它上传成功。我还检查服务器上传大小限制它是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内部服务器错误下面的字符串。我无法粘贴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