簡體   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