2

The following script (just the relevant part) that let me download a file:

if ($file = fopen($file, 'r'))
{
    if(isset($_SERVER['HTTP_RANGE']))
    {
        fseek($file, $range);
    } 
    while(!feof($file) && 
        (!connection_aborted()) && 
        ($bytes_send<$new_length))
    {
        $buffer = fread($file, $chunksize);
        print($buffer); //echo($buffer); // is also possible
        flush();
        $bytes_send += strlen($buffer);
    }
    fclose($file);
}

Doing this, the downloaded file will show the actual time as its creation time.

I would like to know how to preserve the last modification file that it has on the server.

I know I can get the info with filemtime but I don't know how to use it in combination with the script above.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
dop3
  • 391
  • 1
  • 14
  • I'm not sure if I understand what you need, but if you want to update the last access every time maybe you should check the touch function (http://php.net/touch) – mishu Jun 04 '12 at 15:14
  • 1
    You'd need to use more advanced methods to retrieve the headers of the http request and extract the Last-Modified header. You can't do this at all with a basic fread() call. Look into using [streams](http://php.net/streams) or [curl](http://php.net/curl) – Marc B Jun 04 '12 at 15:14
  • mishu: yes, the problem with touch is that i need to "touch" something... with the given script i'm just outputting the raw file content! and so... @MarcB: i'm search for a solution but, right now, i'm not done yet! thanks – dop3 Jun 04 '12 at 15:26

1 Answers1

0

Before sending any output, do

header("Last-Modified: " . gmdate("D, d M Y H:i:s", filemtime($file)) . " GMT");

I don't think this will cause a web browser to save the file locally with that modification time. I think you need to use some type of archive format for that, like zip.

goat
  • 31,486
  • 7
  • 73
  • 96