我正在使用codeigniter为客户创建一个网站,该网站将用于管理pdf格式的学习资源。我想要的是当用户下载pdf,网站测量下载进度然后下载完成时,它在数据库中标记他们已成功下载文件然后不允许他们第二次下载它。
我的问题是测量下载进度。这是我的代码
public function download($id)
{
if($this->ion_auth->logged_in())
{
$user_id = $this->ion_auth->user()->row()->id;
if($user_id != $id){
show_error('We could not find any payment record for this resource. Be sure you have paid or contact us for any queries.');
}
// check resource using otp and resource id
$resource_id = $this->input->get('resource_id', true);
$otp = $this->input->get('otp', true);
$is_valid = $this->downloads_m->validate_resource($resource_id, $otp);
if(!count($is_valid))
{
show_error('The OTP and Resource you have requested do not match our records');
}
if(!$is_valid->pending)
{
show_error('Our records are showing that you have not paid for this resource. Please contact us if you have any query pertaining to this issue');
}
// get file here
$resource = $this->resources_m->get($resource_id, true);
$resource_folder = date('Y_m', strftime(strtotime($resource->created)));
$this->load->helper('download');
force_download('./assets/study_resources/' . $resource_folder . '/' . $resource->slug . '.pdf', null);
}
}
JS
$('.btn-download').on('click', function(){
var $this = $(this);
var url = $this.attr('href');
$.ajax({
url: url,
type: 'POST',
ajaxStart: $this.html('Loading...'),
success: function(d){
console.log(d);
$this.html('<i class="fa fa-download"></i>');
}
});
return false;
});
在开发控制台中,我只得到一个长字符串的网络响应,但它甚至没有开始下载。有什么建议?