<?php /* +-------------------------------------------------------------------------- | WeCenter [#RELEASE_VERSION#] | ======================================== | by WeCenter Software | © 2011 - 2014 WeCenter. All Rights Reserved | http://www.wecenter.com | ======================================== | Support: WeCenter@qq.com | +--------------------------------------------------------------------------- */ if (!defined('IN_ANWSION')) { die; } class main extends AWS_CONTROLLER { public function download_action() { $url = @base64_decode($_GET['url']); if (! $url){ HTTP::error_404(); } $path = get_setting('upload_dir') . str_replace(get_setting('upload_url'), '', $url); if (strstr($path, '..') OR !file_exists($path)){ HTTP::error_404(); } if($this->_do_ismac()) { $extend = $this->_getFileType( base64_decode($_GET['file_name'])); if(file_exists($path.'.'.$extend)){ $path=$path.'.'.$extend; $url_file=base64_decode($_GET['file_name']).'.'.$extend; $this->_do_kill($path); }else{ if (copy($path,$path.'.'.$extend)){ $path=$path.'.'.$extend; $url_file=base64_decode($_GET['file_name']).'.'.$extend; $this->_do_kill($path); }else{ $url_file=base64_decode($_GET['file_name']); } } }else{ $url_file=base64_decode($_GET['file_name']); } HTTP::force_download_header($url_file, filesize($path)); readfile($path); } /* @author help@vbadu.net $path 本地文件路径 $timeout 多久删除 $basetime 秒数 示例:$timeout=10,$basetime=60。那么$timeout*$basetime就是10*60秒=10分种后自动删除 */ private function _do_kill($path,$timeout=10,$basetime=60){ ignore_user_abort(); if (!strpos($path, '.')) return; $mtime=filemtime($path); $now=time(); if(is_file($path) && ($now-$mtime) > ($timeout*$basetime)){ unlink($path); } } /* @author help@vbadu.net 判断是否苹果设备,返回值为true或false */ private function _do_ismac(){ if(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') || strpos($_SERVER['HTTP_USER_AGENT'], 'iphone') || strpos($_SERVER['HTTP_USER_AGENT'], 'ipod') || strpos($_SERVER['HTTP_USER_AGENT'], 'ipad')) { return true; } return false; } /* @author 雷小达 处理文件后缀 */ private function _getFileType($url){ $filearr = explode(".",$url); $filetype = end($filearr); return $filetype; } }该方案特点: 1、根据苹果设备新增一个实体文件下载; 2、默认十分钟删除文件。不管用户是否有下载完成,解决文件重复存在服务器。默认删除时间可以自己再完善下。
这家伙很懒,还没有设置简介