我有一個(gè)非?;镜奈募蟼飨到y(tǒng),使用 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();}我已經(jīng)查過myDropzone.on("success", function(file,response) {
console.log(response.img);
$('#imgResponse').html(response.img);
});在上面的函數(shù)中,我能夠運(yùn)行警報(bào),因此成功事件有效,但是console.log(response.img);不管用。它工作正常,但只是響應(yīng)不正確,因此它在控制臺(tái)中給出未定義的消息。相同的代碼在一臺(tái)服務(wù)器上工作正常,而在另一臺(tái)服務(wù)器上我收到此錯(cuò)誤。我還檢查了服務(wù)器中是否啟用了 json 模塊,并使用示例代碼進(jìn)行編碼和解碼測(cè)試。我還檢查了 phpinfo() 中啟用的顯示。我不明白為什么它在該服務(wù)器上不起作用。讓我知道是否有人可以幫助我解決這個(gè)難題。
Json Encode 在一臺(tái)服務(wù)器上工作,在另一臺(tái)服務(wù)器上工作,給出錯(cuò)誤未定義
慕運(yùn)維8079593
2023-11-11 16:07:44