我正在尝试使用CI 2.1.3使用进度条进行文件上载。我已经将文件上传全部正常工作,但获取这个文件的进度并不容易。我已经看过大量的指南都有不同的解决方案,但是他们都没有工作,因为大多数都相当过时(2008-ish)。CodeIgniter上传进度
这里就是我在寻找:(!没有Flash,请)
- PHP/jQuery的/ AJAX/JavaScript的解决方案
- 跨浏览器(IE不是一个问题,所以如果在IE8无法正常工作或降低这很好)
- 笨上传库兼容
这就是它。我的参考代码:
PHP:
public function do_upload()
{
// Configure and load the uploads library
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'mp4|mov';
$config['encrypt_name'] = TRUE;
$config['max_size'] = '2621440'; // 2.5 GB, in kilobytes
$this->load->library('upload', $config);
if (!$this->upload->do_upload('userfile'))
{
$this->session->set_flashdata('error', $this->upload->display_errors('', ''));
redirect('upload');
}
else
{
$this->session->set_flashdata('upload_data', $this->upload->data());
$upload_data = $this->upload->data();
$uploader = $this->flexi_auth->get_user_by_id()->row_array()['uacc_username'];
$this->load->model('upload_model');
$this->session->set_flashdata('uaid', $this->upload_model->generate_uaid($upload_data['raw_name']));
$this->upload_model->create_upload($upload_data['file_name'], $upload_data['raw_name'], $upload_data['client_name'], $upload_data['file_size'], $upload_data['file_path'], $uploader);
redirect('upload');
}
}
HTML:
<div class="progress progress-striped active" id="upload_progress" style="display: none;">
<div class="bar" id="upload_progress_bar" style="width: 0%;"></div>
</div>
<?php echo form_open_multipart('upload/do_upload', array('id' => 'upload_form')); ?>
<input type="file" name="userfile" size="20" />
<button type="submit" name="upload">Upload</button>
<?php echo form_close(); ?>
看看这个jQuery插件,也许你可以使用它或拿出你在项目中使用的部分关于进度条:http://pixelcone.com/fileuploader/ – 2013-04-11 08:04:46