當前位置:首頁 » 編程語言 » php文件打包下載

php文件打包下載

發布時間: 2023-06-13 20:55:46

1. 怎樣用多文件php實現多文件下載

好可憐啊,誰給你的任務,這個是不可能的,和框架、語言都沒關系,是不是你的上級看錯了文檔啊,人家要求多個文件用zip打包下載(比如把文檔中的「別忘了用zip」看成「別用zip」)

這種只能js同時彈出多窗口了,例如

<formclass="download_form"target="download_url_1"action="download_url_1"></form>
<formclass="download_form"target="download_url_2"action="download_url_2"></form>
...
<buttononclick="$('form.download_form').each(function(){this.submit();})"type="button">點</button>

只要下載是正常的,這種彈出會在用戶操作後(下載或取消)自動消失的。但是用戶要一個一個點還是很差勁的用戶體驗。

window.open也行,但是容易受瀏覽器彈窗設置影響,所以不建議。

2. PHP網頁上打包文件生成壓縮文件zip,並彈出下載

既然你只是想學習如何打包.


那我重點就回答你這一塊,正好我剛剛用到;

$filename="./".date('YmdH').".zip";//最終生成的文件名(含路徑)
//生成文件
$zip=newZipArchive();//使用本類,linux需開啟zlib,windows需取消php_zip.dll前的注釋
if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit('無法打開文件,或者文件創建失敗');
}

//$fileNameArr就是一個存儲文件路徑的數組比如array('/a/1.jpg,/a/2.jpg....');

foreach($fileNameArras$val){
$zip->addFile($val,basename($val));//第二個參數是放在壓縮包中的文件名稱,如果文件可能會有重復,就需要注意一下
}
$zip->close();//關閉

//下面是輸出下載;
header("Cache-Control:max-age=0");
header("Content-Description:FileTransfer");
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);//輸出文件;

3. php打包下載文件源碼

打包,顧名思義,就是打包啊
用zip模塊將選擇的文件打包成一個文件,然後提供下載!
源碼就不提供了,自己學習寫吧

4. thinkphp打包exe

thinkphp 打包文件,並下載

/**
* 打包下載
* 注意文件路徑都是相對路徑
* 不能使用ajax的方式
* @return [type] [description]
*/
public function allzip(){
$param = $this->request->param();

$ids = explode(",",$param['id']);

//要打包的文件
foreach ($ids as $k => $v){
$files[] =substr(db('seofile')->where('id',$v)->value('fileurl'),1);
}

$zip = new \ZipArchive;
//壓縮文件名
$filename = 'upload/file/download.zip';
//新建zip壓縮包
$zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);

//循環壓縮文件
foreach($files as $key => $value){

$zip->addFile($value,basename($value));

}

//打包zip
$zip->close();

header("Cache-Control:public");
header("Content-Description: File Transfer");
header("Content-disposition: attachment; filename=".basename($filename));//文件名
//header("Content-Type: application/force-download");
header("Content-Type:application/zip"); //格式為zip
header("Content-Transfer-Encoding:binary"); //這是二進制文件
header("Content-Length:".filesize($filename)); //文件大小

@readfile($filename);
// @unlink($filename);

}

5. php如何實現文件夾的打包下載詳細操作步驟

publicfunctiondownloads(){
$file="./Ludian_Disaster_Relief_Map_Operation_Guide.pdf";
if(file_exists($file)){
header('Content-Description:FileTransfer');
header('Content-Type:application/octet-stream');
header('Content-Disposition:attachment;filename='.basename($file));
header('Content-Transfer-Encoding:binary');
header('Expires:歷念差0');
header('高尺Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('肢皮Pragma:public');
header('Content-Length:'.filesize($file));
ob_clean();
flush();
readfile($file);
}else{
$this->error("文件不存在");

}
}

6. php 如何把文件夾及文件夾下面的所有文件打包成壓縮包,在頁面上用戶點擊下載按鈕即可下載到本地

一般不會下載的時候重新打包,因為php打包是一個凳改拿非常消耗資源的過程棗搭。
使用php zip 打包,然後記錄包的路徑,下載的時候直接下殲乎載該路徑文件即可。

7. 求大神幫把php文件給我打包成zip的、謝啦

1,芹滾賀程序操作:PHP的zip文備者件長傳到附件了,放在網站的根目錄就行了。
2,不同操嫌派作:選擇PHP文件滑鼠右鍵進行軟體打包。

熱點內容
查詢重復欄位的sql語句 發布:2025-02-13 03:12:42 瀏覽:322
8uftp上傳網站 發布:2025-02-13 03:01:57 瀏覽:242
電腦玩游戲如何配置電源 發布:2025-02-13 03:01:53 瀏覽:361
微信怎麼上傳頭像不了 發布:2025-02-13 02:57:04 瀏覽:118
c語言矩陣的轉置 發布:2025-02-13 02:38:43 瀏覽:624
rowphp 發布:2025-02-13 02:37:16 瀏覽:711
光遇安卓服周年傘在哪裡領取 發布:2025-02-13 02:22:18 瀏覽:674
寫mv腳本軟體 發布:2025-02-13 02:21:56 瀏覽:696
超內核源碼 發布:2025-02-13 02:12:54 瀏覽:444
趣粉腳本 發布:2025-02-13 02:11:23 瀏覽:952