本文整理汇总了PHP中Http::download方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::download方法的具体用法?PHP Http::download怎么用?PHP Http::download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Http
的用法示例。
在下文中一共展示了Http::download方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: file_download
public function file_download()
{
$uploadpath = './Uploads/file/';
//设置文件上传路径,服务器上的绝对路径
$id = $_GET['id'];
//GET方式传到此方法中的参数id,即文件在数据库里的保存id.根据之查找文件信息。
if ($id == '') {
//如果id为空而出错时,程序跳转到项目的Index/index页面。或可做其他处理。
$this->display('没有找到该文件', U('Index/Index/index'));
}
$file = M('file');
//利用与表file对应的数据模型类FileModel来建立数据对象。
$result = $file->find($id);
//根据id查询到文件信息
if ($result == false) {
//如果查询不到文件信息而出错时,程序跳转到项目的Index/index页面。或可做其他处理
$this->display('没有找到该文件', U('Index/Index/index'));
}
$savename = $file->file_savename;
//文件保存名
$showname = $file->file_truename;
//文件原名
$filename = $uploadpath . $savename;
//完整文件名(路径加名字)
//print_r($filename);die;
import('ORG.Net.Http');
Http::download($filename, $showname);
}
示例2: saveTickets
function saveTickets($sql, $filename, $how = 'csv')
{
ob_start();
self::dumpTickets($sql, $how);
$stuff = ob_get_contents();
ob_end_clean();
if ($stuff) {
Http::download($filename, "text/{$how}", $stuff);
}
return false;
}
示例3: download
public function download()
{
import('ORG.Net.Http');
header("Content-Type:text/html;charset=UTF-8");
$title = I('get.title');
$file_dir = './Public/upload/';
$Resource = D('Resource');
$map['id'] = I('get.id');
$list = $Resource->where($map)->order('id desc')->find();
$name = $list['content'];
$filename = $file_dir . $name;
$download = new Http();
$download->download($filename, $showtitle);
}
示例4: download
public function download()
{
import("@.ORG.Http");
$id = $_GET['id'];
$dao = M("Attach");
$attach = $dao->where("id=" . $id)->find();
$filename = $attach["savepath"] . $attach["savename"];
if (is_file($filename)) {
if (!isset($_SESSION['attach_down_count_' . $id])) {
$dao->setInc('downCount', "id=" . $id);
$_SESSION['attach_down_count_' . $id] = true;
}
Http::download($filename, $attach->name);
}
}
示例5: get_file
protected function get_file($field, $error_empty = '', $error_unreachable = '')
{
if (empty($field)) {
throw new Error_Api($error_empty, Error_Api::MISSING_INPUT);
}
if (strlen($field) < self::MAX_URL_LENGTH && parse_url($field)) {
$data = Http::download($field);
$error = $error_unreachable;
} else {
$data = base64_decode($field);
$error = 'Некорректный формат передачи бинарных данных. Они были закодированы в base64?';
}
if (empty($data)) {
throw new Error_Api($error, Error_Api::INCORRECT_INPUT);
}
return $data;
}
示例6: index
function index()
{
$aid = intval($_REQUEST['id']);
$uid = intval($_REQUEST['uid']);
$attach = D('Attach')->where("id='{$aid}' AND userId='{$uid}'")->find();
if (!$attach) {
$this->error('附件不存在或已被删除!');
}
//下载函数
import("ORG.Net.Http");
//调用下载类
if (file_exists(UPLOAD_PATH . $attach['savepath'] . $attach['savename'])) {
$filename = iconv("utf-8", 'gb2312', $attach['savename']);
Http::download(UPLOAD_PATH . $attach['savepath'] . $attach['savename'], $filename);
} else {
$this->error('附件不存在或已被删除!');
}
}
示例7: download
public function download()
{
$aid = intval($_REQUEST['id']);
$uid = intval($_REQUEST['uid']);
$attach = model('Xattach')->where("id='{$aid}' AND uid='{$uid}'")->find();
//$attach = model('Xattach')->where("id='$aid'")->find();
if (!$attach) {
$this->error('附件不存在或已被删除!');
}
//下载函数
//import("ORG.Net.Http"); //调用下载类
require_cache('./addons/libs/Think/Http.class.php');
if (file_exists(UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename'])) {
//增加下载次数
model('Xattach')->setInc('totaldowns', "id='{$aid}'");
//输出文件
$filename = $attach['name'];
$filename = auto_charset($filename, "UTF-8", 'GBK');
//$filename = 'attach_'.$attach['id'].'.'.$attach['extension'];
Http::download(UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename'], $filename);
} else {
$this->error('附件不存在或已被删除!');
}
}
示例8: download
/**
* 下载附件
*
* @param int $aid 附件ID 为空时使用$_REQUEST['id']作为附件ID
*/
public function download($aid)
{
if (intval($aid) == 0) {
$aid = intval($_REQUEST['id']);
}
$attach = M('Attach')->where("id='{$aid}'")->find();
if (!$attach) {
$this->error('附件不存在或已被删除!');
}
//下载函数
require_cache('./addons/libs/Think/Http.class.php');
if (file_exists(UPLOAD_PATH . $attach['savepath'] . $attach['savename'])) {
$filename = iconv("utf-8", 'gb2312', $attach['savename']);
Http::download(UPLOAD_PATH . $attach['savepath'] . $attach['savename'], $filename);
} else {
$this->error('附件不存在或已被删除!');
}
}
示例9: log_export
public function log_export()
{
if (!IS_POST) {
$this->message2('', '失败', 0);
}
$log_model = new Model('kongbao_order');
$userid = session('userid');
$where['user_id'] = $userid;
$where['order_status'] = 1;
$keyword = I('keyword', NULL);
$ftype = I('ftype', NULL);
if (!empty($keyword) && !empty($ftype)) {
$where[$ftype] = array('like', '%' . $keyword . '%');
}
$type_id = I('type_id', '');
if ($type_id != '') {
$where['type_id'] = $type_id;
}
$log_list = $log_model->where($where)->order('order_time desc')->select();
$log_array = array();
$kb_type = M('kongbao_type')->select();
$type_array = array();
foreach ($kb_type as $type) {
$type_array[$type['id']] = $type['name'];
}
$i = 0;
foreach ($log_list as $k => $log) {
$i++;
$log_temp = array();
$log_temp[] = $i;
$log_temp[] = $type_array[$log['type_id']];
$log_temp[] = $log['order_time'];
$log_temp[] = $log['note_no'];
$log_temp[] = $log['send_province'] . '-' . $log['send_city'] . '-' . $log['send_district'];
$log_temp[] = $log['rec_province'] . '-' . $log['rec_city'] . '-' . $log['rec_district'] . $log['rec_address'];
$log_temp[] = $log['rec_name'];
$log_array[] = $log_temp;
}
$headers = array(array('序号', '快递类型', '下单时间', '单号', '发货地址', '收货地址', '收货人'));
$order_counts = count($log_array);
$file_name = $userid . '-' . $order_counts . '-' . time();
$fileurl = 'Public/Uploads/kb_log/' . $userid . '/';
MkdirAll($fileurl);
$filename = $file_name . '.xls';
$fileurl = $fileurl . md5($file_name) . '.xls';
include 'Public/PHPExcel/PHPExcel.php';
include 'Public/PHPExcel/PHPExcel/Writer/Excel5.php';
include 'Public/PHPExcel/PHPExcel/Cell/DataType.php';
$m_objPHPExcel = new PHPExcel();
$this->write_xls($m_objPHPExcel, $fileurl, $headers, $log_array);
import('ORG.Net.Http');
ob_end_clean();
$download = new Http();
$download->download($fileurl, $filename);
exit;
}
示例10: downloadTabularData
function downloadTabularData()
{
$data = $this->getData();
$csv = '"' . implode('","', $data['columns']) . '"';
foreach ($data['data'] as $row) {
$csv .= "\n" . '"' . implode('","', $row) . '"';
}
Http::download(sprintf('%s-report.csv', $this->get('group', __('Department'))), 'text/csv', $csv);
}
示例11: download
/**
* 下载附件
*
* @param int $aid 附件ID 为空时使用$_REQUEST['id']作为附件ID
*/
public function download($aid)
{
if (intval($aid) == 0) {
$aid = intval($_REQUEST['id']);
}
$attach = model('Attach')->field('savepath,savename,name')->where("id='{$aid}'")->find();
if (!$attach) {
$this->error('附件不存在或已被删除!');
}
//下载函数
require_cache('./addons/libs/Http.class.php');
$file_path = UPLOAD_PATH . '/' . $attach['savepath'] . $attach['savename'];
if (file_exists($file_path)) {
$filename = strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? iconv('utf-8', 'gbk', $attach['name']) : preg_replace('/\\s/', '_', $attach['name']);
Http::download($file_path, $filename);
} else {
$this->error('附件不存在或已被删除!');
}
}
示例12: download
function download($disposition = false, $expires = false)
{
$disposition = $disposition ?: 'inline';
$bk = $this->open();
if ($bk->sendRedirectUrl($disposition)) {
return;
}
$ttl = $expires ? $expires - Misc::gmtime() : false;
$this->makeCacheable($ttl);
Http::download($this->getName(), $this->getType() ?: 'application/octet-stream', null, $disposition);
header('Content-Length: ' . $this->getSize());
$this->sendData(false);
exit;
}
示例13: outputData
/**
* 导出SQL文件
* @access public
* @return void
*/
public function outputData()
{
if (empty($_POST['table'])) {
// 默认导出所有表
$tables = $this->db->getTables(Session('useDb'));
} else {
// 导出指定表
$tables = explode(',', $_POST['table']);
}
$this->db->execute('USE ' . Session('useDb'));
// 组装导出SQL
$sql = "-- ThinkPHP SQL Dump\n-- http://www.thinkphp.cn\n\n";
foreach ($tables as $key => $table) {
$sql .= "-- \n-- 表的结构 `{$table}`\n-- \n";
$info = $this->db->query("SHOW CREATE TABLE {$table}");
$sql .= $info[0]['Create Table'];
$sql .= ";\n-- \n-- 导出表中的数据 `{$table}`\n--\n";
$result = $this->db->query("SELECT * FROM {$table} ");
foreach ($result as $key => $val) {
foreach ($val as $k => $field) {
if (is_string($field)) {
$val[$k] = '\'' . $this->db->escapeString($field) . '\'';
} elseif (empty($field)) {
$val[$k] = 'NULL';
}
}
$sql .= "INSERT INTO `{$table}` VALUES (" . implode(',', $val) . ");\n";
}
}
$filename = empty($_POST['table']) ? Session('useDb') : $_POST['table'];
import("ORG.Net.Http");
if (empty($_POST['zip'])) {
file_put_contents(C('TEMP_PATH') . $filename . '.sql', trim($sql));
Http::download(C('TEMP_PATH') . $filename . '.sql');
} else {
$zip = new \ZipArchive();
if ($zip->open(C('TEMP_PATH') . $filename . '.zip', \ZIPARCHIVE::CREATE) !== TRUE) {
exit("cannot open <{$filename}>\n");
}
$zip->addFromString($filename . '.sql', trim($sql));
//$zip->addFile(TEMP_PATH.'thinkcms.sql',"ddd/test.sql");
$zip->close();
Http::download(C('TEMP_PATH') . $filename . '.zip');
}
/*
if(empty($_POST['zip'])) {
import("ORG.Net.Http");
Http::download (TEMP_PATH.$filename.'.sql');
}else{
import('Think.Util.Archive');
$archive = new Archive($_POST['zip']);
switch(strtolower($_POST['zip'])) {
case 'gzip':$ext = '.tar.gz';break;
case 'bzip':$ext = '.tar.bz2';break;
case 'tar':$ext = '.tar';break;
case 'zip':
default:$ext = '.zip';
}
$archive->add(TEMP_PATH.$filename.'.sql',$filename.'.sql',TRUE);
$archive->download($filename.$ext);
}*/
}
示例14: downfile
public function downfile()
{
$filename = I('file', '');
if ($filename == '') {
$this->message2('无效请求!', U('database'));
}
$bkdir = 'Public/Uploads/backupdata';
$filepath = $bkdir . '/' . $filename;
if (!file_exists($filepath)) {
$this->message2('未找到备份文件!', U('database'));
}
$file_path = iconv('utf-8', 'gb2312', $filepath);
import('ORG.Net.Http');
$download = new Http();
$download->download($file_path, $filename);
}
示例15: download
public function download($file = null)
{
return Http::download('public/' . $file);
}