Php中 readfile() 檔案大小如何設定?

來源:互聯網
上載者:User

標籤:

本文和大家分享的主要是php readfile() 檔案大小設定相關內容,一起來看看吧,希望對大家學習php有所協助。

使用PHP ZipArchive產生的壓縮包,小的壓縮包都能下載,今天遇到個150M以上的就報404錯誤,第一想到的就是檔案大小超出了PHP預設設定,修改方法有兩個:

php.ini:memory_limit

memory_limit是設定記憶體限制的,如果使用readfile()讀取檔案就會和這個有關,直接修改這個值儲存後重啟php-fpm即可。

memory_limit = 128M

最後記得:service php-fpm restart

ini_set

PHP ini_set用來設定php.ini的值,在函數執行的時候生效,那我們直接用來修改記憶體執行大小即可,有些朋友用的如果是虛擬空間的話,這個函數就是救星了。

ini_set(’memory_limit’, ’512M’);

完整的樣本:

set_time_limit(0);

ini_set(’memory_limit’, ’512M’);

header("Cache-Control: public");

header("Content-Description: File Transfer");

header(’Content-disposition: attachment; filename=’ . basename($zipfile));

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

header("Content-Transfer-Encoding: binary");

header(’Content-Length: ’ . filesize($zipfile));

ob_clean();flush();

@readfile($zipfile);

unlink($zipfile);

 

 

來源:體驗盒子

Php中 readfile() 檔案大小如何設定?

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.