第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

強(qiáng)制文件下載處理

強(qiáng)制文件下載處理

PHP
搖曳的薔薇 2023-04-02 10:19:07
我試圖了解如何為強(qiáng)制下載創(chuàng)建響應(yīng)以及瀏覽器如何處理它。在此處關(guān)注本文:教程。我有一個發(fā)送文件作為下載響應(yīng)的腳本。<?php// it's a zip fileheader('Content-Type: application/zip');// 1 million bytes (about 1megabyte)header('Content-Length: 1000000');// load a download dialogue, and save it as download.zipheader('Content-Disposition: attachment; filename="download.zip"');// 1000 times 1000 bytes of datafor ($i = 0; $i < 1000; $i++) {    echo str_repeat(".",1000);    // sleep to slow down the download    // sleep(5);}sleep(5);當(dāng)sleep()函數(shù)在循環(huán)內(nèi)時,它會在文件開始下載之前等待一段時間。但是當(dāng)放在循環(huán)之外時,文件會立即開始下載。誰能幫我理解這種行為?
查看完整描述

1 回答

?
揚(yáng)帆大魚

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個贊

第二種情況的問題是在調(diào)用睡眠函數(shù)之前將文件發(fā)送給客戶端。您可以將輸出存儲在內(nèi)部緩沖區(qū)中,并在睡眠功能之后發(fā)送。(我不建議將其用于生產(chǎn)。)試試這個修改后的程序:


<?php

// it's a zip file

header('Content-Type: application/zip');

// 1 million bytes (about 1megabyte)

header('Content-Length: 1000000');

// load a download dialogue, and save it as download.zip

header('Content-Disposition: attachment; filename="download.zip"');


//Turn on output buffering

ob_start();


// 1000 times 1000 bytes of data

for ($i = 0; $i < 1000; $i++) {

    echo str_repeat(".",1000);


    // sleep to slow down the download

    // sleep(5);

}


//Store the contents of the output buffer

$buffer = ob_get_contents();

// Clean the output buffer and turn off output buffering

ob_end_clean();


sleep(5);


echo $buffer;


查看完整回答
反對 回復(fù) 2023-04-02
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號