I\'m currently using dropzone.js v3.10.2 I am having issues displaying my existing files I have already uploaded. I am more than competent with php however I have limited kn
I'm leaving here the solution that worked for me. (Dropzone v5.7.0 and Codeigniter v3.1.11)
in my App controller:
public function ilan_fotolari($ilan_id = 0)
{
$this->load->helper('ilan');
$dirPath = './assets/uploads/'.ilan_dir($ilan_id);
$this->load->helper('file');
$file_names = get_filenames($dirPath);
$mocks = [];
foreach ($file_names as $file_name) {
$mock['name'] = $file_name;
$dirUrl = base_url('assets/uploads/'.ilan_dir($ilan_id));
$mock['url'] = $dirUrl.$file_name;
$mocks[] = $mock;
}
$this->output
->set_content_type('application/json')
->set_output(json_encode($mocks));
}
in my script.js:
Dropzone.options.ilanFotoAlani = {
paramName: "foto", // The name that will be used to transfer the file
maxFilesize: 5, // MB
maxFiles: 9,
resizeWidth: 1000,
resizeHeight: 644,
resizeMimeType: 'image/jpeg',
addRemoveLinks: true,
dictDefaultMessage: 'Fotoğraf sürükle veya seç',
dictFileTooBig: 'Fotoğraf boyutu en fazla 5MB olmalı',
dictRemoveFile: 'Fotoğrafı sil',
dictCancelUpload: 'İptal et',
dictMaxFilesExceeded: 'En fazla 9 fotoğraf yükleyebilirsin',
init: function () {
let myDropzone = this;
$.ajax({
type: 'get',
url: '/ilan-fotolari',
success: function(mocks){
$.each(mocks, function(key,value) {
let mockFile = { name: value.name, size: 1024 };
myDropzone.displayExistingFile(mockFile, value.url);
});
},
error: function(xhr, durum, hata) {
alert("Hata: " + hata);
}
});
}
};
I have mixed up solutions from different solutions into this.