导航:首页 > 编程语言 > 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下载文件大小相关的资料

热点内容
android怎么搭建框架 浏览:172
正宗溯源码大燕条一克一般多少钱 浏览:917
电脑感染exe文件夹 浏览:916
wpsppt怎么转pdf格式 浏览:88
腾讯文档在线编辑怎么添加密码 浏览:880
本地不能访问服务器地址 浏览:865
访问服务器命令 浏览:835
华为云服务器分销商 浏览:954
Linux定位内存泄露 浏览:198
工程加密狗视频 浏览:720
不在内网怎么连接服务器 浏览:664
云服务器app安卓下载 浏览:966
如何查看linux服务器的核心数 浏览:137
交易平台小程序源码下载 浏览:148
程序员记笔记用什么app免费的 浏览:646
java与单片机 浏览:897
服务器内网如何通过公网映射 浏览:478
程序员穿越到宋代 浏览:624
怎么使用云服务器挂游戏 浏览:620
真实的幸福pdf 浏览:346