本文目錄一覽:
- 1、php 如何把文件夾及文件夾下面的所有文件打包成壓縮包,在頁面上用戶點擊下載按鈕即可下載到本地?
- 2、php導出excel表後,打包成壓縮包,然後下載到本地如何實現?
- 3、php如何實現兩個文件先壓縮成一個壓縮包然後下載
- 4、下載一個zip文件 怎麼用php實現
- 5、php 上傳RAR壓縮文件,在頁面中有個“點擊下載”的連接,點擊則下載此文件
php 如何把文件夾及文件夾下面的所有文件打包成壓縮包,在頁面上用戶點擊下載按鈕即可下載到本地?
一般不會下載的時候重新打包,因為php打包是一個非常消耗資源的過程。
使用php zip 打包,然後記錄包的路徑,下載的時候直接下載該路徑文件即可。
php導出excel表後,打包成壓縮包,然後下載到本地如何實現?
用PHPExcel,PHPExcel是相當強大的 MS Office Excel 文檔生成類庫。
你上它的官/網把程序包下/載下來,裡面有 PHPExcel 的程序、還有30個實例程序和三個文檔。
看一下其中的開發文檔你就會用了。
讀取(這段在開發文檔里有的,在13頁):
require_once ‘../Classes/PHPExcel/IOFactory.php’;
$objReader = PHPExcel_IOFactory::createReader(‘Excel2007’);
$objReader-setReadDataOnly(true);
$objPHPExcel = $objReader-load(“test.xlsx”);
$objWorksheet = $objPHPExcel-getActiveSheet();
echo ‘table’ . “\n”;
foreach ($objWorksheet-getRowIterator() as $row) {
echo ‘tr’ . “\n”;
$cellIterator = $row-getCellIterator();
$cellIterator-setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo ‘td’ . $cell-getValue() . ‘/td’ . “\n”;
}
echo ‘/tr’ . “\n”;
}
echo ‘/table’ . “\n”;
?
php如何實現兩個文件先壓縮成一個壓縮包然後下載
$filename = “./” . date ( ‘YmdH’ ) . “.zip”; // 最終生成的文件名(含路徑)
// 生成文件
$zip = new ZipArchive (); // 使用本類,linux需開啟zlib,windows需取消php_zip.dll前的注釋
if ($zip-open ( $filename, ZIPARCHIVE::CREATE ) !== TRUE) {
exit ( ‘無法打開文件,或者文件創建失敗’ );
}
//$fileNameArr 就是一個存儲文件路徑的數組 比如 array(‘/a/1.jpg,/a/2.jpg….’);
foreach ( $fileNameArr as $val ) {
$zip-addFile ( $val, basename ( $val ) ); // 第二個參數是放在壓縮包中的文件名稱,如果文件可能會有重複,就需要注意一下
}
$zip-close (); // 關閉
//下面是輸出下載;
header ( “Cache-Control: max-age=0” );
header ( “Content-Description: File Transfer” );
header ( ‘Content-disposition: attachment; filename=’ . basename ( $filename ) ); // 文件名
header ( “Content-Type: application/zip” ); // zip格式的
header ( “Content-Transfer-Encoding: binary” ); // 告訴瀏覽器,這是二進制文件
header ( ‘Content-Length: ‘ . filesize ( $filename ) ); // 告訴瀏覽器,文件大小
@readfile ( $filename );//輸出文件;
下載一個zip文件 怎麼用php實現
wnload.php 文件部分, 根據自己的需要修改一下 //———————- 中間的部分即可
?php
class zipfile {
var $datasec = array ();
var $ctrl_dir = array ();
var $eof_ctrl_dir = “\x50\x4b\x05\x06\x00\x00\x00\x00”;
var $old_offset = 0;
function unix2_dostime($unixtime = 0){
$timearray = ($unixtime == 0) ? getdate () : getdate($unixtime);
if ($timearray [‘year’] 1980){
$timearray [‘year’] = 1980;
$timearray [‘mon’] = 1;
$timearray [‘mday’] = 1;
$timearray [‘hours’] = 0;
$timearray [‘minutes’] = 0;
$timearray [‘seconds’] = 0;
}
return (($timearray [‘year’] – 1980) 25) | ($timearray [‘mon’] 21) | ($timearray [‘mday’] 16) | ($timearray [‘hours’] 11) | ($timearray [‘minutes’] 5) | ($timearray [‘seconds’] 1);
}
function add_file($data, $name, $time = 0){
$name = str_replace(‘\\’, ‘/’, $name);
$dtime = dechex($this-unix2_dostime($time));
$hexdtime = ‘\x’ . $dtime [6] . $dtime [7] . ‘\x’ . $dtime [4] . $dtime [5] . ‘\x’ . $dtime [2] . $dtime [3] . ‘\x’ . $dtime [0] . $dtime [1];
eval(‘$hexdtime = “‘ . $hexdtime . ‘”;’);
$fr = “\x50\x4b\x03\x04”;
$fr .= “\x14\x00”;
$fr .= “\x00\x00”;
$fr .= “\x08\x00”;
$fr .= $hexdtime;
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gz……一帆風順吉星到 萬事如意福臨門 財源廣進
php 上傳RAR壓縮文件,在頁面中有個“點擊下載”的連接,點擊則下載此文件
html
a href=”download.php?id=xxx”/a
download.php
?php
$id = $_GET[‘id’];
$sql=”SELECT `name`,`path` FROM `table` WHERE `id`=’$id'”;
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if(file_exists($row[‘path’])){
$file = fopen($row[‘path’], ‘r’);
header(‘Content-Type: application/octet-stream’);
header(‘Accept-Ranges: bytes’);
header(‘Accept-Length: ‘.filesize($row[‘path’]));
header(‘Content-Disposition: attachment; filename=’.$row[‘name’]);
echo fread($file, filesize($row[‘path’]));
fclose($file);
}else{
echo ‘指定的文件不存在’;
}
?
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/254831.html