導航:首頁 > 編程語言 > php下載文件大小

php下載文件大小

發布時間:2022-07-28 01:14:26

① 如何用php下載比較大的文件,比如說300-400M的文件 - PHP進階討論

如果用PHP來讀大文件,簡單應用倒還好,做專門的下載不可行吧?PHP做來源判斷還好,但是不能夠完全屏蔽一些流氓軟體。我覺得吧PHP和web伺服器不是專門做文件下載的,如果真要用,那就用伺服器插件
+
經過特別優化的服務端咯。

② 大家看一下我這段php代碼,為什麼文件下載到200M左右時就停止了

可能是操過了單個php能使用的最大內存數了。你把php內存使用改大一點試試。

③ apache或者php有沒有設置限制下載文件大小的參數

沒有這種參數,應該是腳本的有效期過了。

④ php 文件下載問題

header( "Pragma: public" );
header( "Expires: 0" ); // set expiration time
header( "Content-Type: application/force-download;" ); //告訴瀏覽器強制下載
header( "Content-Transfer-Encoding: binary" );
header( "Cache-control: private" );
header( "Pragma: no-cache" ); //不緩存頁面
header( "Cache-Component: must-revalidate, post-check=0, pre-check=0" );
header( "Content-type:".$this->mineType );
header( "Content-Length: " . filesize( $this->filename ) );
header( "Content-Disposition: attachment; filename=\"$fn\"" );
header( 'Content-Transfer-Encoding: binary' );

添加這些設置
把中間的PHP換成你自己的文件問, 文件大小, 文件類型等, 就可以了

⑤ php下載函數,在ie上不能下載大於2G的文件,當文件大於2G的時候,下載下的壓縮文件是0KB的,求大神指點。

/**
* 發送文件
*
* @author: legend([email protected])
* @link: http://www.ugia.cn/?p=109
* @description: send file to client
* @version: 1.0
*
* @param string $fileName 文件名稱或路徑
* @param string $fancyName 自定義的文件名,為空則使用filename
* @param boolean $forceDownload 是否強制下載
* @param integer $speedLimit 速度限制,單位為位元組,0為不限制,不支持windows伺服器
* @param string $$contentType 文件類型,默認為application/octet-stream
*
* @return boolean
*/
function sendFile($fileName, $fancyName = '', $forceDownload = true, $speedLimit = 0, $contentType = '')
{
if (!is_readable($fileName))
{
header("HTTP/1.1 404 Not Found");
return false;
}
$fileStat = stat($fileName);
$lastModified = $fileStat['mtime'];
$md5 = md5($fileStat['mtime'] .'='. $fileStat['ino'] .'='. $fileStat['size']);
$etag = '"' . $md5 . '-' . crc32($md5) . '"';
header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $lastModified) . ' GMT');
header("ETag: $etag");
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModified)
{
header("HTTP/1.1 304 Not Modified");
return true;
}
if (isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) < $lastModified)
{
header("HTTP/1.1 304 Not Modified");
return true;
}
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
{
header("HTTP/1.1 304 Not Modified");
return true;
}
if ($fancyName == '')
{
$fancyName = basename($fileName);
}
if ($contentType == '')
{
$contentType = 'application/octet-stream';
}
$fileSize = $fileStat['size'];
$contentLength = $fileSize;
$isPartial = false;
if (isset($_SERVER['HTTP_RANGE']))
{
if (preg_match('/^bytes=(d*)-(d*)$/', $_SERVER['HTTP_RANGE'], $matches))
{
$startPos = $matches[1];
$endPos = $matches[2];
if ($startPos == '' && $endPos == '')
{
return false;
}
if ($startPos == '')
{
$startPos = $fileSize - $endPos;
$endPos = $fileSize - 1;
}
else if ($endPos == '')
{
$endPos = $fileSize - 1;
}
$startPos = $startPos < 0 ? 0 : $startPos;
$endPos = $endPos > $fileSize - 1 ? $fileSize - 1 : $endPos;
$length = $endPos - $startPos + 1;
if ($length < 0)
{
return false;
}
$contentLength = $length;
$isPartial = true;
}
}
// send headers
if ($isPartial)
{
header('HTTP/1.1 206 Partial Content');
header("Content-Range: bytes $startPos-$endPos/$fileSize");
}
else
{
header("HTTP/1.1 200 OK");
$startPos = 0;
$endPos = $contentLength - 1;
}
header('Pragma: cache');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Accept-Ranges: bytes');
header('Content-type: ' . $contentType);
header('Content-Length: ' . $contentLength);
if ($forceDownload)
{
header('Content-Disposition: attachment; filename="' . rawurlencode($fancyName). '"');
}
header("Content-Transfer-Encoding: binary");
$bufferSize = 2048;
if ($speedLimit != 0)
{
$packetTime = floor($bufferSize * 1000000 / $speedLimit);
}
$bytesSent = 0;
$fp = fopen($fileName, "rb");
fseek($fp, $startPos);
//fpassthru($fp);
while ($bytesSent < $contentLength && !feof($fp) && connection_status() == 0 )
{
if ($speedLimit != 0)
{
list($usec, $sec) = explode(" ", microtime());
$outputTimeStart = ((float)$usec + (float)$sec);
}
$readBufferSize = $contentLength - $bytesSent < $bufferSize ? $contentLength - $bytesSent : $bufferSize;
$buffer = fread($fp, $readBufferSize);
echo $buffer;
ob_flush();
flush();
$bytesSent += $readBufferSize;
if ($speedLimit != 0)
{
list($usec, $sec) = explode(" ", microtime());
$outputTimeEnd = ((float)$usec + (float)$sec);
$useTime = ((float) $outputTimeEnd - (float) $outputTimeStart) * 1000000;
$sleepTime = round($packetTime - $useTime);
if ($sleepTime > 0)
{
usleep($sleepTime);
}
}
}
return true;
}

⑥ 在嗎能不能給我一段php下載代碼,要顯示文件大小啊,我在網上找的能下載文件但都顯示未知文件大小。

$user_file='要下載的文件路徑';
header("Content-Type:application/force-download");
header("Content-Disposition:attachment;filename=".basename($user_file));
readfile($user_file);

⑦ php做的下載功能,為什麼點擊下載不提示文件大小代碼里有寫啊

其實是這個函數的問題,我最近研究了很久,終於明白了。代碼如下。
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Content-Length: ".$filesize);
header("Content-Disposition: attachment; filename=「.$filename);
原理就是Accept-Length換成Content-length,這樣就可以了

閱讀全文

與php下載文件大小相關的資料

熱點內容
正宗溯源碼大燕條一克一般多少錢 瀏覽:915
電腦感染exe文件夾 瀏覽:914
wpsppt怎麼轉pdf格式 瀏覽:86
騰訊文檔在線編輯怎麼添加密碼 瀏覽:868
本地不能訪問伺服器地址 瀏覽:865
訪問伺服器命令 瀏覽:835
華為雲伺服器分銷商 瀏覽:954
Linux定位內存泄露 瀏覽:198
工程加密狗視頻 瀏覽:720
不在內網怎麼連接伺服器 瀏覽:664
雲伺服器app安卓下載 瀏覽:966
如何查看linux伺服器的核心數 瀏覽:137
交易平台小程序源碼下載 瀏覽:148
程序員記筆記用什麼app免費的 瀏覽:646
java與單片機 瀏覽:897
伺服器內網如何通過公網映射 瀏覽:478
程序員穿越到宋代 瀏覽:624
怎麼使用雲伺服器掛游戲 瀏覽:618
真實的幸福pdf 瀏覽:345
d盤php調用c盤的mysql 瀏覽:267