Autor Zpráva
maroslukac
Profil
Dobry večer prajem,

Chcel by som sa opýtať, ako sa da obísť memory_limit tak, aby som mohol stiahnuť súbor väčši ako memory_limit: 260MB. Bohužiaľ, memory_limit u webhosting providera je fixnuty na 260MB, takže viac MB si neprihodim nijak. Viete mi poradiť? Ďakujem.

PHP 'download' script:

$result = array(
            'volume'  => $volume,
            'pointer' => $fp,
            'info'    => $file,
            'header'  => array(
                'Content-Type: '.$mime, 
                'Content-Disposition: '.$disp.'; '.$filename,
                'Content-Location: '.$file['name'],
                'Content-Transfer-Encoding: binary',
                'Content-Length: '.$file['size'],
                'Connection: close'
            )
        );
        return $result;
    }
Alphard
Profil
Ten script toho moc neprozrazuje. PHP memory limit by měl jít obejít funkcí readfile(), ale vysypat tak velký soubor na výstup taky asi nebude ideální (s tímto nemám až tak velké zkušenosti). Lze použít průběžné odesílání dat (fopen a po částech načítat), jenže to zase na delší dobu zabere vlákno (ta mohou být omezená). Osobně bych nechal PHP download samotný delegovat na http server.
maroslukac
Profil
Možno prezradi viac:

   /**
     * Required to output file in browser when volume URL is not set 
     * Return array contains opened file pointer, root itself and required headers
     *
     * @param  array  command arguments
     * @return array
     * @author Dmitry (dio) Levashov
     **/

protected function file($args) {
        $target   = $args['target'];
        $download = !empty($args['download']);
        $h403     = 'HTTP/1.x 403 Access Denied';
        $h404     = 'HTTP/1.x 404 Not Found';

       if (($volume = $this->volume($target)) == false) { 
            return array('error' => 'File not found', 'header' => $h404, 'raw' => true);
        }
        
       if (($file = $volume->file($target)) == false) {
            return array('error' => 'File not found', 'header' => $h404, 'raw' => true);
        }
        
       if (!$file['read']) {
            return array('error' => 'Access denied', 'header' => $h403, 'raw' => true);
        }
        
       if (($fp = $volume->open($target)) == false) {
            return array('error' => 'File not found', 'header' => $h404, 'raw' => true);
        }

       if ($download) {
            $disp = 'attachment';
            $mime = 'application/octet-stream';
        } else {
            $disp  = preg_match('/^(image|text)/i', $file['mime']) || $file['mime'] == 'application/x-shockwave-flash' 
                    ? 'inline' 
                    : 'attachment';
            $mime = $file['mime'];
        }
        
       $filenameEncoded = rawurlencode($file['name']);
        if (strpos($filenameEncoded, '%') === false) { // ASCII only
            $filename = 'filename="'.$file['name'].'"';
        } else {
            $ua = $_SERVER["HTTP_USER_AGENT"];
            if (preg_match('/MSIE [4-8]/', $ua)) { // IE < 9 do not support RFC 6266 (RFC 2231/RFC 5987)
                $filename = 'filename="'.$filenameEncoded.'"';
            } else { // RFC 6266 (RFC 2231/RFC 5987)
                $filename = 'filename*=UTF-8\'\''.$filenameEncoded;
            }
        }
        
       $result = array(
            'volume'  => $volume,
            'pointer' => $fp,
            'info'    => $file,
            'header'  => array(
                'Content-Type: '.$mime, 
                'Content-Disposition: '.$disp.'; '.$filename,
                'Content-Location: '.$file['name'],
                'Content-Transfer-Encoding: binary',
                'Content-Length: '.$file['size'],
                'Connection: close'
            )
        );
        
        return $result;
    }

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0