欢迎各位兄弟 发布技术文章
这里的技术是共享的
1)下载
<?php
/**
* download page
*
* @author shipingzhong <shipingzhong@altech-it.cn>
* @version 20090525
*/
session_cache_limiter("public"); // for IE
// read user common file
//include this file.... and it has smarty function
require_once("./include/User.inc.php");
$uid = $_SESSION['sess_marry_user']['user_id'];
$wid = $_SESSION['sess_marry_user']['wedding_id'];
//download?dl=1&pid={$dataRow.photo_id}"
if (empty($uid))
{
header("location :".HTTP_URL);
}
$pid = $_GET['pid'];
$userIdInImage = $Download->getUserIdInImage($pid);
$dataRow = $Photo->getOne($pid, $userIdInImage);
//session_start(); // session_start() in here is error .I don not know
$file_name = $dataRow['photo_real_name']."." .$dataRow['extension'];
$uid = $_SESSION['sess_marry_user']['user_id'];
$file_path = PHOTO_PATH . $wid . "/" . $file_name;
$showFileName = $dataRow['photo_base_name'];
$showFileName = mb_convert_encoding($showFileName, "SJIS", "UTF-8");
Header("Content-type: application/octet-stream");
//Header("Content-type: application/txt");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_path));
//把 attachment 改成 inline 应该就是打开 好像不行 我暂时也不懂inline什么意思
//Header("Content-Disposition: attachment; filename=" . $showFileName);
Header("Content-Disposition: attachment; filename=\"$showFileName\"");
//殷
$fp=fopen($file_path, "r");//非文本文件最好用 "rb"
echo fread($fp, filesize($file_path));
fclose($fp);
//
//exit;
?>
下载第二个例子
<?php
if(isset($_GET['url'])){
$filename=$_GET['url'];//获取参数
header('Content-type: image/jpeg');
header("Content-Disposition: attachment; filename=eweimanet".date('YmdHis').rand(100,999).".jpg");
readfile($filename);
//注意:header函数前确保没有任何输出
exit;//结束程序
}
?>
2)打开文件