Laravel 5.6 Ajax发布500内部服务器错误

时间:2018-07-21 07:09:09

标签: php jquery ajax laravel laravel-5.6

你好,我通过Ajax Post Request发送大字符串数据,并且在本地主机上工作正常,但是在实时服务器上不工作,我正在发送一些图像数据,然后将此图像数据转换为服务器上的图像。这也花费了很多时间发送此数据的平均数据大小在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';

1 个答案:

答案 0 :(得分:0)

  

Blockquote   您是否仅收到错误500,而没有其他信息?如果是这样,请启用调试,以便您可以更好地描述错误。确保您的php.ini文件设置正确,并且服务器文件夹的权限也合适(我总是会遇到存储文件夹的问题)。