日志文件:tdnlog.log 大小:752MB下载类 function download($filepath, $filename = '') {
if(!$filename) $filename = basename($filepath);
if(is_ie()) $filename = rawurlencode($filename);
$filetype = fileext($filename);
$filesize = sprintf("%u", filesize($filepath));
if(ob_get_length() !== false) @ob_end_clean();
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: none');
header('Content-type: '.$filetype);
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-length: '.$filesize);
readfile($filepath);
exit;
}文件在100MB之内正常 但超过就会报下面的错误 我把php.ini里面的memory_limit设置为512MB也不管用 这是怎么个情况啊
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 750743553 bytes) in /var/www/nms/framebase/libs/functions/extention.func.php on line 233
有一种解决办法是压缩为zip包phpmyadmin的数据库导出下载就不会出现这个 它那个也没压缩 看了半天phpmyadmin的代码 各种混乱和纠结 求助吧

解决方案 »

  1.   

    那就再改大点。800MB,900MB,1G  ....都试下。
      

  2.   

    哥哥 这个解决了 方法如下 不用加memory_limit就行 /**
     * 文件下载
     * @param $fileName 服务器文件路径
     * @param $fancyName 下载文件名字(默认为服务器文件名)
     * @param $forceDownload 是否许可用户下载方式(默认可选)
     * @param $speedLimit 速度限制(默认自动)
     * @param $contentType 文件类型(默认所有)
     */
    function downFile($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);
    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;
    }感谢写这个方法的人 开源精神 必须好好研究 大家也看看吧 好了 散分吧 哈哈哈