Php file_get_contents (): content truncated from 2147483648 to 2147483647 bytes

How can I find out when I am going to create a zip file from a 2 GB file.

Error

file_get_contents (): content truncated from 2147483648 to 2147483647 bytes

Fatal error: Out of memory (2151677952 allocated) (tried to allocate 18446744071562067968 bytes) in

I am using a dedicated server and have already installed memory_limit,max_execution_time,max_upload_filesize,max_post_size. But it does not work for me. Please check my code and let me know what I am doing wrong -

create a new zip object

    $zip = new ZipArchive();

    # create a temp file & open it
    $tmp_file = tempnam('.','');
    $zip->open($tmp_file, ZipArchive::CREATE);

    # loop through each file
    foreach($files as $file){
        # download file
        $download_file = file_get_contents($file_path.'/'.$file);
        #add it to the zip
        $zip->addFromString(basename($file_path.'/'.$file),$download_file);
    }

    # close zip
    $zip->close();
    $zip_name = $last_seg.'.zip';
    # send the file to the browser as a download
    header("Content-disposition: attachment; filename=$zip_name");
    header('Content-type: application/zip');
    readfile($tmp_file);
+4
source share
3 answers

$zip->addFromString() $zip->addFile(), , , 3- ( ), $zip->addFile() , zip 3gb.

set_time_limit(0);

, :

$files //Array of files name $file_path //Path where your files ($files) are placed $last_seg //The name of your zip file

<?php

    set_time_limit(0);

    $files = array('Exodus.mp4', 'the-expert.webm', 'what-virgin-means.webm');
    $file_path = 'zip';
    $last_seg = 'test';

    $zip = new ZipArchive();

    # create a temp file & open it
    $tmp_file = tempnam('.','');
    $zip->open($tmp_file, ZipArchive::CREATE);

    # loop through each file
    foreach($files as $file){
        $zip->addFile($file_path.'/'.$file, $file);
    }

    # close zip
    $zip->close();
    $zip_name = $last_seg.'.zip';
    # send the file to the browser as a download
    header("Content-disposition: attachment; filename=$zip_name");
    header('Content-type: application/zip');
    readfile($tmp_file);

?>

:

http://php.net/manual/en/ziparchive.addfile.php

+5

, PHP_INT_MAX. , , Linux- x64 PHP , file_gets_content int 32bits, Windows 32- .

- : ( )

$fr = fopen("http://...", "r");
$fw = fopen("zip://c:\\test.zip#test", "w");

while(false !== ($buffer = fread($fr, 8192)))
{
  fwrite($fw, $buffer, strlen($buffer));
}

fclose($fr);
fclose($fw);

, , -, PHP "+ w" zip... , temp ( , , file_get_contents) , ( system() popen call...) (, php zlib ant bzip2) php.

+4

:

ini_set("memory_limit", -1);

: ( 1134559232) ( 32768 ) X:\wamp\www\xxx

-3
source

All Articles