我是OpenCart的初学者,我正在尝试使用PHP在服务器上传文件。我已经完成了以下代码。我的问题是,文件是在服务器上成功上传但如果有一些错误我正在尝试加载LoadA()
功能,但结果没有在网站上显示而是显示在console.log
我不知道不知道错误是什么。
控制器/ boxupload / upload.php的
public function add()
{
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file))
{
if(success) //files are succesfully uploading
{
//doing stuff
}
if (it is fail)
{
$this->LoadA(); // this is not loading in site. Instead it is showing in console.log
}
}
}
public function LoadA()
{
$data['token'] = $this->session->data['token'];
$this->document->setTitle("!!!!!!!!!!!!Upload failed!!!!!!!!");
$data['add'] = $this->url->link('boxupload/upload/add', 'token=' . $this->session->data['token'], 'SSL');
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('boxupload/upload.tpl', $data));
}
然后是这个的tpl文件
控制器/ boxupload / upload.tpl
$('#button-upload').on('click', function() {
$('#progress-bar').css('width', '0%');
$('#form-upload').remove();
$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');
$('#form-upload input[name=\'file\']').trigger('click');
if (typeof timer != 'undefined') {
clearInterval(timer);
}
var WID = 30;
timer = setInterval(function() {
if ($('#form-upload input[name=\'file\']').val() != '') {
clearInterval(timer);
// Reset everything
$('.alert').remove();
$('#progress-bar').css('width', '0%');
$('#progress-bar').removeClass('progress-bar-danger progress-bar-success');
$('#progress-text').html('');
$.ajax({
url: '<?php echo "index.php?route=boxupload/upload/add&token=$token"; ?>',
type: 'post',
//dataType: 'json',
data: new FormData($('#form-upload')[0]),
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
$('#button-upload').button('loading');
$('#progress-bar').css('width', '50%');
},
complete: function() {
$('#button-upload').button('reset');
$('#progress-bar').css('width', '100%');
},
success: function()
{ $('#progress-bar').css('width', '80%');
},
});
}
}, 500);
});
答案 0 :(得分:1)
试试这个:
dataType: 'html',
success: function(html)
{
$('#progress-bar').css('width', '80%');
$('#your-div').html(html);
},
答案 1 :(得分:1)
您的.tpl文件应该在视图中。
$this->response->setOutput($this->load->view('boxupload/upload.tpl', $data));
加载文件
view/theme/default/template/boxupload/upload.tpl
另外,查看其他一些模板文件。它们通常主要是HTML。
此外,您将要重构您的名称,以便他们使用正常的OpenCart命名约定。
controller/extension/boxupload/upload.php
view/theme/default/template/extension/boxupload/upload.tpl
etc.