2011-02-14 68 views
7

我的一位客户决定将网站从一个不错的服务器移动到...让我们称之为更好的服务器。文件在php下载,内存限制问题?

的问题是,有一个与40MBs文件下载和服务器上的内存限制为32。为了使它更加困难对我来说,他们不容许的fopen ...

而且,如果我将文件大小减小到20MB,它可以正常工作。

所以,我的问题是,除了减小文件大小外,我还能做些什么?

谢谢

编辑:`

 $fsize = filesize($file_path); 
     $path_parts = pathinfo($file_path); 
     $ext = strtolower($path_parts["extension"]); 


     switch ($ext) { 
      case "pdf": $ctype = "application/pdf"; 
       break; 
      case "exe": $ctype = "application/octet-stream"; 
       break; 
      case "zip": $ctype = "application/zip"; 
       break; 
      case "doc": $ctype = "application/msword"; 
       break; 
      case "xls": $ctype = "application/vnd.ms-excel"; 
       break; 
      case "ppt": $ctype = "application/vnd.ms-powerpoint"; 
       break; 
      case "gif": $ctype = "image/gif"; 
       break; 
      case "png": $ctype = "image/png"; 
       break; 
      case "jpeg": 
      case "jpg": $ctype = "image/jpg"; 
       break; 
      default: $ctype = "application/force-download"; 
     } 

     header("Pragma: public"); // required 
     header("Expires: 0"); 
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
     header("Cache-Control: private", false); // required for certain browsers 
     header("Content-Type: $ctype"); 
     header("Content-Disposition: attachment; filename=\"" . basename($file_path) . "\";"); 
     header("Content-Transfer-Encoding: binary"); 
     header("Content-Length: " . $fsize); 
     ob_clean(); 
     flush(); 
     readfile($file_path);` 

我看到php.net

// If it's a large file, readfile might not be able to do it in one go, so: 
$chunksize = 1 * (1024 * 1024); // how many bytes per chunk 
if ($size > $chunksize) { 
    $handle = fopen($realpath, 'rb'); 
    $buffer = ''; 
    while (!feof($handle)) { 
    $buffer = fread($handle, $chunksize); 
    echo $buffer; 
    ob_flush(); 
    flush(); 
    } 
    fclose($handle); 
} else { 
    readfile($realpath); 
} 
+0

phpinfo的核心部分是什么样的?你能粘贴它吗?如果您正在寻找一个快速解决方案,您可以使用.htaccess文件更改您的php设置。他们是drupal文档,但他们不是drupal特定的。 http://drupal.org/node/29268和http://drupal.org/node/97193 – KyleWpppd 2011-02-14 04:23:27

+0

特别是任何部分? (在这里发布所有内容有点大) – 2011-02-15 23:57:03

回答

3

使用readfile()不是代码。它将以小块形式传输文件,并处理所有后台工作,以最大限度地减少内存使用量。