我正在尝试将图像存储在文件夹中,但是由于以下原因,当我调用图像时会给出404:http://localhost/xxxx/new/item/77/public/images/item/77/2.jpg我没有如何删除“ new / item / 77 /”并将图像保存到正确的文件夹中的方法:我的JavaScript$(".dropzone").dropzone({ init: function() { myDropzone = this; $.ajax({ url: 'image/get', type: 'post', data: {request: 'fetch'}, dataType: 'json', success: function(response){ $.each(response, function(key,value) { var mockFile = { name: value.name, size: value.size}; myDropzone.emit("addedfile", mockFile); myDropzone.emit("thumbnail", mockFile, value.path); myDropzone.emit("complete", mockFile); }); } });}});我的路线Route::post('new/item/{id}/image/get','ItemController@fileGet'); 我的控制器 public function fileGet(Request $request){ $fileList = []; $targetDir= 'public/images/item/77/'; $dir = $targetDir; if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ if($file != '' && $file != '.' && $file != '..'){ $file_path = $targetDir.$file; if(!is_dir($file_path)){ $size = filesize($file_path); $fileList[] = ['name'=>$file, 'size'=>$size, 'path'=>$file_path]; } } } closedir($dh); } } echo json_encode($fileList);exit;}我期望的是http://localhost/xxxx/public/images/item/77/2.jpg或者,如果有人知道一种更好的方式来获取存储在dropzone.js提示中的文件!
1 回答
- 1 回答
- 0 关注
- 156 浏览
添加回答
举报
0/150
提交
取消