我是OpenCart的初學者,我試圖使用PHP在服務器上傳文件。我已經完成了下面的代碼。我的問題是,文件在服務器上成功上傳,但如果有一些錯誤,我試圖加載LoadA()
函數,但結果沒有顯示在網站上,而是顯示在console.log
我不知道錯誤是什麼。OpenCart未在頁面加載內容?
控制器/ 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);
});
您需要調用$ this-> LoadA();而不是$ this-> load(); ? –
也如果我沒有錯,你需要設置成功或錯誤,如下這樣的HTML: 成功:功能(html){ \t \t $('#div-name')。html(html); }, ,因爲你有html的回覆 –