php - Joomla uploading images issue -
i installed bt property component joomla site , when select multiple of images (more 3 or 4) want upload article, nothing happens. images won't upload. try change code don't know problem is.
this code want change.
<?php defined('_jexec') or die('restricted access'); $document = jfactory::getdocument(); $path = $this->params->get('images_path', 'images/bt_property'); ?> <ul class="adminformlist" id="uploading"> <li><input type="file" name="attachment" id="attachment" multiple /><img id="spinner" style="display: none; margin-left: 10px;" src="<?php echo juri::root(); ?>components/com_bt_property/assets/img/spinner.gif"> <div style="clear: both"></div> <div id="btss-message"></div></li> </ul> <script type="text/javascript"> (function($){ var files = []; $("#attachment").change(function(event) { $.each(event.target.files, function(index, file) { var reader = new filereader(); reader.onload = function(event) { object = {}; object.filename = file.name; object.data = event.target.result; files.push(object); if(files.length==1){ uploadfile(index); $('#spinner').show(); $("#btss-message").show(); } }; reader.readasdataurl(file); }); }); function uploadfile(index){ $.ajax({url: "index.php?option=com_bt_property&task=properties.upload", type: 'post', data: {filename: files[index].filename, filedata: files[index].data}, success: function(response, status, xhr){ uploadhandler(response, status, xhr); if(index == files.length-1){ $('#spinner').hide(); files = []; $("#attachment").val(''); $("#btss-message").delay(1000).slideup(function(){ $("#btss-message").html(''); }); }else{ index++; uploadfile(index); } } }); } function uploadhandler(response, status, xhr) { var data = jquery.parsejson(response); if(data == null){ showmessage("<br /><span style=\"color: red;\">loading failed</span>"); }else{ var file = data.files; if (!data.success) { showmessage("<br /><span style=\"color: red;\"> " + data.message +"</span>"); } else { var html = '<li>'; html += '<input class="input-default" title="make default" name="default_image" type="radio" value="'+file.filename+'" />'; html += '<img class="img-thumb" src="<?php echo juri::root() . $path . '/tmp/' . ($this->params->get('thumbimgprocess', 1) == -1 ? 'original' : 'thumb') . '-'; ?>'+file.filename+'" />'; html += '<input type="hidden" name="image_id[]" value="0" />'; html += '<input type="hidden" name="image_filename[]" value="'+file.filename+'" /><br/>'; html +='<a href="javascript:void(0)" class="edit" onclick="editimage(this)">edit</a>'; html +='<a href="javascript:void(0)" class="remove" onclick="removeimage(this)" >remove</a>'; html += '</li>'; jquery('#sortable').append(html); jquery('#sortable li:last-child ').find('a.edit').data('title', file.title); renewitem(); showmessage('<br />' + file.title + " uploaded successfully!"); } } } function showmessage(msg){ $("#btss-message").append(msg); } })(jquery); </script>
is there way fix code? thankful answer.
your file
object coming undefined, , you're not able use file.filename
.
your problem line var file = data.files;
- sure data.files
?
Comments
Post a Comment