码迷,mamicode.com
首页 > Web开发 > 详细

通过php下载文件并重命名

时间:2014-09-13 17:15:35      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   文件   div   sp   

$filename = dirname(__FILE__) . ‘/oldfilename.jpg‘;
$out_filename = ‘newfilename.jpg‘;
if( ! file_exists($filename)){
  echo ‘Not Found‘ . $filename;
  exit;
} else {
  // We‘ll be outputting a file
  header(‘Accept-Ranges: bytes‘);
  header(‘Accept-Length: ‘ . filesize($filename));
  // It will be called
  header(‘Content-Transfer-Encoding: binary‘);
  header(‘Content-type: application/octet-stream‘);
  header(‘Content-Disposition: attachment; filename=‘ . $out_filename);
  header(‘Content-Type: application/octet-stream; name=‘ . $out_filename);
  // The source is in filename
if(is_file($filename) && is_readable($filename)){     $file = fopen($filename, "r");     echo fread($file, filesize($filename));     fclose($file);
}   
exit; }

 

通过php下载文件并重命名

标签:style   blog   color   io   os   ar   文件   div   sp   

原文地址:http://www.cnblogs.com/caly/p/3970005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!