hi iam trying to use blueimp jQuery file upload with codeigniter but i need to load existing files by id inserted in database
this is function in my controller
public function get_files()
{
$last = $this->uri->total_segments();
$record_num = $this->uri->segment($last);
if (is_numeric($record_num) == TRUE) {
$upload_path_url = base_url() . 'uploads/';
$config['upload_path'] = FCPATH . 'uploads/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['max_size'] = '30000';
$existingFiles = get_dir_file_info($config['upload_path']);
$foundFiles = array();
$f=0;
foreach ($existingFiles as $fileName => $info) {
if($fileName!='thumbs'){//Skip over thumbs directory
//set the data for the json array
$foundFiles[$f]['name'] = $fileName;
$foundFiles[$f]['size'] = $info['size'];
$foundFiles[$f]['url'] = $upload_path_url . $fileName;
$foundFiles[$f]['thumbnailUrl'] = $upload_path_url . 'thumbs/' . $fileName;
$foundFiles[$f]['deleteUrl'] = base_url() . 'http://ift.tt/2akxtQW' . $fileName;
$foundFiles[$f]['deleteType'] = 'DELETE';
$foundFiles[$f]['error'] = null;
$f++;
}
}
$this->output
->set_content_type('application/json')
->set_output(json_encode(array('files' => $foundFiles)));
and in main.js
// Load existing files:
$('#fileupload').addClass('fileupload-processing');
$.ajax({
// Uncomment the following to send cross-domain cookies:
//xhrFields: {withCredentials: true},
// url: $('#fileupload').fileupload('option', 'url'),
url: 'http://localhost/mysite/index.php/App/controll/get_files',
dataType: 'json',
context: $('#fileupload')[0]
}).always(function () {
$(this).removeClass('fileupload-processing');
}).done(function (result) {
$(this).fileupload('option', 'done')
.call(this, $.Event('done'), {result: result});
});
but this if statement if (is_numeric($record_num) == TRUE)
didn't work
Aucun commentaire:
Enregistrer un commentaire