【问题标题】:Laravel 5.6 Ajax Post 500 Internal Server ErrorLaravel 5.6 Ajax Post 500 内部服务器错误
【发布时间】:2018-07-21 07:09:08
【问题描述】:

您好,我正在通过 Ajax Post Request 发送大型字符串数据,它在 localhost 上工作正常,但在实时服务器上无法正常工作发送此数据的平均数据大小在 4 到 7 MB 之间..您还可以建议一个更好的方法,以便可以快速完成..而且设置正确我包括 CSRF 令牌和 URL 也很好,但不知道为什么会出现这个错误

错误 => 状态码:500 内部服务器错误

我发送请求的控制器代码

$pid    =  $request->input('id');
        $pt_id  =  $request->input('pt_id');
        $pname  =  $request->input('name');
        $isBack =  $request->input('isBack');
        $qty    =  $request->input('qty');
        $paper  =  $request->input('paper');
        $previewFront  =  $request->input('previewFront');
        $previewBack   =  $request->input('previewBack');
        $PrintDataFront  =  $request->input('PrintDataFront');
        $PrintDataBack   =  $request->input('PrintDataBack');
        $cart_item_id = uniqid();
        //Store Img Data
        $pf = str_replace('data:image/png;base64,', '', $previewFront);
        $pf = str_replace(' ', '+', $pf);
        $pf_n = $cart_item_id.'_f_.'.'png';
        \File::put(public_path(). '/cart_preview/' . $pf_n, base64_decode($pf));
        $pb = str_replace('data:image/png;base64,', '', $previewBack);
        $pb = str_replace(' ', '+', $pb);
        $pb_n = $cart_item_id.'_b_.'.'png';
        \File::put(public_path(). '/cart_preview/' . $pb_n, base64_decode($pb));
        $pdf = str_replace('data:image/png;base64,', '', $PrintDataFront);
        $pdf = str_replace(' ', '+', $pdf);
        $pdf_n = $cart_item_id.'_f_.'.'png';
        \File::put(public_path(). '/orders/' . $pdf_n, base64_decode($pdf));
        $pdb = str_replace('data:image/png;base64,', '', $PrintDataBack);
        $pdb = str_replace(' ', '+', $pdb);
        $pdb_n = $cart_item_id.'_b_.'.'png';
        \File::put(public_path(). '/orders/' . $pdb_n, base64_decode($pdb));
        //Get Prices and qty
        $opriceitem = PriceTableItem::find($qty);
        $itemQty = $opriceitem->qty;
        $basePrice = $opriceitem->total;
        if($isBack == 'true') {
            $backPrice =  $opriceitem->total_back;
            $itemPrice = $opriceitem->total + $opriceitem->total_back;
            $pricePerPiece = $opriceitem->item_price + $opriceitem->item_price_back;            
        }else {
            $backPrice =  'INCLUDED';
            $itemPrice = $opriceitem->total; 
            $pricePerPiece = $opriceitem->item_price; 
        }
        if($paper == 'Premium White') {
            $paperPrice = ($itemPrice/100) *60;
            $itemPrice = $itemPrice + ($itemPrice/100) *60;
        } else {
            $paperPrice = 'INCLUDED';
        }
        //Get all Available Qty
        $allQty = PriceTableItem::where('tid', $pt_id)->get();
        $allAvailableQty = array();
        foreach($allQty as $allqtyarry) {array_push($allAvailableQty, $allqtyarry->qty);}       
        //Create Cart Object
        $item = [
            "id"      => $cart_item_id,
            "pid"      => $pid,
            "name"    => $pname,
            "qty"     => $itemQty,
            "price_table_id"    => $pt_id,
            "paperType"  => $paper,
            "backCharges"  => $backPrice,
            "paperCharges"  => $paperPrice,
            "isBack" => $isBack,
            "pricePerPiece"    => $pricePerPiece,
            "basePrice"    => $basePrice,
            "totalPrice"    => $itemPrice,
            "allQty"    => $allAvailableQty,
        ];
        $request->session()->put('cart.items.' . $cart_item_id, $item);
        return 'Success';

【问题讨论】:

  • 你的服务器上有图片吗?
  • 不,服务器上没有保存图像
  • 请考虑一下。 PHP是服务器端代码。在您的代码中,您将获得 .png 文件。对吗?
  • 我知道 php 是服务器端代码..它在 localhost 上运行良好,但在实时服务器上却不行
  • 在实时服务器上,没有任何图像。如果你愿意,你应该上传图片。 PHP 代码无法从本地 PC 获取任何内容。

标签: php jquery ajax laravel laravel-5.6


【解决方案1】:

块引用 你只得到错误 500 而没有别的吗?如果是这样,请启用调试,以便您可以更好地描述错误。确保您的 php.ini 文件设置正确,并且您的服务器文件夹的权限也很好(我总是遇到存储文件夹的问题)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-22
    • 2017-03-07
    • 2019-12-05
    • 2016-04-08
    • 2014-12-01
    • 2018-02-04
    • 1970-01-01
    • 2019-11-12
    相关资源
    最近更新 更多