亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Json Encode 在一臺服務器上工作,在另一臺服務器上工作,給出錯誤未定義

Json Encode 在一臺服務器上工作,在另一臺服務器上工作,給出錯誤未定義

慕運維8079593 2023-11-11 16:07:44
我有一個非?;镜奈募蟼飨到y,使用 PHP 和 Dropzone。上傳PHP文件如下<?phperror_reporting(E_ALL);    // define absolute folder path    $brand = $_POST['brand'];    $reference = $_POST['reference'];    $dest_folder = 'images/'.$brand.'/';    $url = 'https://www.example.com/testupload/'; if(!empty($_FILES)) {    if(!file_exists($dest_folder) && !is_dir($dest_folder)) mkdir($dest_folder);    foreach($_FILES['file']['tmp_name'] as $key => $value) {                $ext = strtolower(pathinfo($_FILES['file']['name'][$key],PATHINFO_EXTENSION));                       if(file_exists($dest_folder) && !is_dir($dest_folder)){             continue;        }else{            mkdir($dest_folder);        }                 $imgName =  $brand."-".$reference.'-picture'.$key.'.'.$ext;                $tempFile = $_FILES['file']['tmp_name'][$key];        $targetFile =  $dest_folder.$imgName;        move_uploaded_file($tempFile,$targetFile);    }                 $dir = $dest_folder;        $data = scandir($dir);        $arr = [];                        foreach($data as $key=>$dataVal)        {            if($dataVal!='.' && $dataVal!='..'){                                                    $arr[] = $url.$dir.$dataVal;                                         }        }                 $imgstring = implode(",",$arr);            /**     *  Response      *  return json response to the dropzone     *  @var data array     */    $data = [        "file" =>$brand,        "dropzone" => $_POST["dropzone"],        "img"=>$imgstring    ];        file_put_contents('abc.txt',$data);        header('Content-type: application/json');    echo json_encode($data);    exit();}我已經查過myDropzone.on("success", function(file,response) {         console.log(response.img);         $('#imgResponse').html(response.img);     });在上面的函數中,我能夠運行警報,因此成功事件有效,但是console.log(response.img);不管用。它工作正常,但只是響應不正確,因此它在控制臺中給出未定義的消息。相同的代碼在一臺服務器上工作正常,而在另一臺服務器上我收到此錯誤。我還檢查了服務器中是否啟用了 json 模塊,并使用示例代碼進行編碼和解碼測試。我還檢查了 phpinfo() 中啟用的顯示。我不明白為什么它在該服務器上不起作用。讓我知道是否有人可以幫助我解決這個難題。
查看完整描述

2 回答

?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

確保兩臺服務器都收到您的文件??雌饋矸掌魃嫌绣e誤,您的文件未上傳,這就是您收到空響應的原因



查看完整回答
反對 回復 2023-11-11
?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

請注釋掉 PHP 腳本中的以下 2 行。

  1. file_put_contents('abc.txt',$data);

  2. header('Content-type: application/json');

并替換error_reporting(E_ALL);error_reporting(0); 它將關閉服務器響應的警告消息。


查看完整回答
反對 回復 2023-11-11
  • 2 回答
  • 0 關注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號