PHP

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • send a file or stream

    0 answers - 5952 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I think the stations.zip is empty Try this:
    Between your scripting and the readfile() put a sleep(2); between so it waits 2 seconds before pushing the data.
    And I also suggest:
    while()
    {
    fwrite($da, "$somevar1:$somevar2");
    }
    fclose($da);
    Header()
    (try sleep(2); here)
    readfile();
    Message
    From: Rafael Mora [mailto:moraloco (AT) gmail (DOT) com]
    Sent: Thursday, August 31, 2006 1:25 AM
    To: Peter Lauri
    Cc: php-general
    Subject: Re: [PHP] send a file or stream
    I can download it, but when I see the file I downloaded has 0 bytes, and I
    have readfile("stations.zip");
    8/30/06, Peter Lauri <lists (AT) dwsasia (DOT) comwrote:
    But can you download it correctly? Is it just the download box that shows
    0 bytes?
    is it so that you actually is doing what you do below readfile()
    without any argument? So that you are actually downloading something empty?
    :)
    /Peter
    >
    >
    >

    Message
    From: Rafael Mora [mailto:moraloco (AT) gmail (DOT) com]
    Sent: Wednesday, August 30, 2006 8:00 PM
    To: php-general (AT) lists (DOT) php.net
    Subject: Re: [PHP] send a file or stream
    Hi!!
    Well it works now, but with another issue, when I download it, it says
    that
    it size is 0 bytes!!
    i fwrite the file in a while, is it correct?
    header()
    while()
    {
    fwrite($da, "$somevar1:$somevar2");
    }
    fclose($da);
    readfile();
    thanks
    >
    >
    >

    8/30/06, Peter Lauri <lists (AT) dwsasia (DOT) comwrote:
    Try this:
    header("Pragma: public");
    header("Expires: 0"); // set expiration time
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/octet-stream");
    header('Content-Disposition: attachment; filename="stations.gzip"');
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize(stations.gzip));
    readfile("stations.gzip");
    /Peter
    PS! To maintain the list and its functionality, do not post same message
    multiple times DS!
    --
    Message
    From: Rafael Mora [mailto:moraloco (AT) gmail (DOT) com]
    Sent: Wednesday, August 30, 2006 11:01 AM
    To: Peter Lauri
    Cc: php-general (AT) lists (DOT) php.net
    Subject: Re: [PHP] send a file or stream
    it works, but it returns me the same .php file, not the one I am
    creating
    >
    >
    >

    8/29/06, Peter Lauri <lists (AT) dwsasia (DOT) comwrote:
    You need to make sure that you are not outputting ANYTHING before you
    do
    this. I might guess that you have a whitespace in the top of the
    script.
    As
    soon as you output, the server can not send any more header
    information,
    and
    the browser will think it is just text instead of treating it as an
    octet-stream.
    >
    >
    >

    /Peter
    >
    >
    >

    From: Rafael Mora [mailto:moraloco (AT) gmail (DOT) com]
    Sent: Wednesday, August 30, 2006 10:25 AM
    To: Peter Lauri
    Cc: php-general (AT) lists (DOT) php.net
    Subject: Re: [PHP] send a file or stream
    >
    >
    >

    I test it and gave me this: ,VD'=(r)(?/C0/D!!
    $D(3/] L so the user should read that? this is my code:
    >
    >
    >

    <?php
    $params = array('level' =6, 'window' =15, 'memory' =9);
    $texto_original = "This is a test.\nThis is only a test.\nThis is not
    an
    important string.\n";
    //echo "El texto original tiene " . strlen($texto_original) . "
    caracteres.\n";
    $da = fopen('stations.gzip', 'w');
    stream_filter_append($da, 'zlib.deflate', STREAM_FILTER_WRITE,
    $params);
    fwrite($da, $texto_original);
    fclose($da);
    header("Content-Type: application/octet-stream");
    readfile("stations.gzip");
    >
    >
    >
    >
    >

    8/29/06, Peter Lauri <lists (AT) dwsasia (DOT) comwrote:
    <?php
    header("Content-Type: application/octet-stream");
    readfile("path_to_compressed_file");
    ?>
    >
    >
    >

    Should do it then. if you know the path to the file :)
    >
    >
    >

    From: Rafael Mora [mailto:moraloco (AT) gmail (DOT) com]
    Sent: Wednesday, August 30, 2006 10:10 AM
    To: Peter Lauri
    Subject: Re: [PHP] send a file or stream
    >
    >
    >

    1. A user sends a request to your server to get a compressed file
    2. You compress the file on the server
    3. I want to send back the file to the user
    >
    >
    >
    >
    >
    >
    >

    8/29/06, Peter Lauri <lists (AT) dwsasia (DOT) comwrote:
    Do you mean the following:
    1. A user sends a request to your server to get a compressed file
    2. You compress the file on the server
    3. You want to send back to compressed file to the server
    It is number 3 you asking for?
    In that case:
    <?php
    header("Content-Type: application/octet-stream");
    readfile("path_to_compressed_file");
    ?>
    /Peter
    --
    Message
    From: Rafael Mora [mailto:moraloco (AT) gmail (DOT) com]
    Sent: Wednesday, August 30, 2006 2:34 AM
    To: php-general (AT) lists (DOT) php.net
    Subject: [PHP] send a file or stream
    Hi!
    i want to send a file or output stream in a .php, but first compress
    it,
    I
    tryed the example to compress files but how do i do to send as answer
    to
    the
    http request?
    Rafa
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >

Re: send a file or stream


max 4000 letters.
Your nickname that display:
In order to stop the spam: 9 + 8 =
QUESTION ON "PHP"

EMSDN.COM