【问题标题】:Getting stored images with Dropzone.js使用 Dropzone.js 获取存储的图像
【发布时间】:2019-09-10 02:18:32
【问题描述】:

我正在尝试获取存储在文件夹中的图像,但是当我调用图像时会给出 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 中的文件 谢谢!

【问题讨论】:

    标签: javascript php laravel routes dropzone.js


    【解决方案1】:
     $(".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);
    
          });
    
        }
      });
    }
     });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多