douluan5523 2019-04-19 21:39
浏览 263

使用Dropzone.js获取存储的图像

I am trying getting the images stored at folder, but the when i am calling the images give 404 because of this:

http://localhost/xxxx/new/item/77/public/images/item/77/2.jpg

i don't no how to remove "new/item/77/" and get the image to the correct folder:

My 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);

      });

    }
  });
}
});

My route

Route::post('new/item/{id}/image/get','ItemController@fileGet');    

My Controller

 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;

}

What i expect is

http://localhost/xxxx/public/images/item/77/2.jpg

Or if any one knows a better way to get the files stored in the dropzone.js Thnaks!

  • 写回答

1条回答 默认 最新

  • douhe4336 2019-04-19 23:46
    关注
     $(".dropzone").dropzone({
    
    init: function() {
      Dropzone = this;
      $.ajax({
        url: APP_URL + '/image/get',
        type: 'post',
        dataType: 'json',
        success: function(response){
    
          $.each(response, function(key,value) {
            var mockFile = { name: value.name, size: value.size};
    
    Dropzone.options.addedfile.call(Dropzone, mockFile);
    Dropzone.options.thumbnail.call(Dropzone, mockFile, APP_URL+"/"+value.path);
    Dropzone.options.complete.call(Dropzone, mockFile);
    
          });
    
        }
      });
    }
     });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记