0

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!

José Neves
  • 130
  • 1
  • 1
  • 9

1 Answers1

0
 $(".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);

      });

    }
  });
}
 });
José Neves
  • 130
  • 1
  • 1
  • 9