Date and Filetime of a HTTP-File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hanjo Grüßner

    Date and Filetime of a HTTP-File

    Hello,

    I want to transfer a file from a http-server to another.
    Well, that goes fine like this:

    $upload = ftp_put($conn_i d, "$destination_f ile", "$source_fi le",
    FTP_BINARY);

    But I want - before the transfer - to know wether the $source_file exists.
    More, I want to know and keep its original filetime.

    I tried with file_exists. Don't work. So don't work fileatime etc. either.

    How ?

    TIA

    Hanjo


    --
    Software & Seminar-Kontor Hans-Joachim Grüßner
    Glasholz
    D-24369 Waabs
    The premium domain gruessner.de is for sale on fruits.co. Secure the domain now and start your online success story. Safe payment and quick transfer are guaranteed.

  • Kirsten

    #2
    Re: Date and Filetime of a HTTP-File

    Hanjo Grüßner schrieb:[color=blue]
    >
    > But I want - before the transfer - to know wether the $source_file exists.
    > More, I want to know and keep its original filetime.[/color]
    Same answer as in de.comp.lang.ph p.misc :-)
    TRy to open the file
    $fp = fopen("path/filename","r")
    I think it is not possible to keep the date, because the file is created
    in the file system therfor it becomes the current date.[color=blue]
    >
    > I tried with file_exists. Don't work. So don't work fileatime etc. either.[/color]
    This function works only lacal not on remote systems.

    -Kirsten

    Comment

    • alex

      #3
      Re: Date and Filetime of a HTTP-File

      > But I want - before the transfer - to know wether the $source_file
      exists.

      try fopen function.
      [color=blue]
      > More, I want to know and keep its original filetime.[/color]

      do you mean date/time on last modification ?
      do you want it locally or remotely ?

      --
      alex


      Comment

      • Hanjo Grüßner

        #4
        Re: Date and Filetime of a HTTP-File

        Am Wed, 28 Sep 2005 16:08:30 +0200 schrieb alex <alex@nospam.or g>:

        [color=blue]
        >
        > try fopen function.
        >[color=green]
        >> More, I want to know and keep its original filetime.[/color]
        >
        > do you mean date/time on last modification ?
        > do you want it locally or remotely ?
        >[/color]

        Hello,

        and thanks.
        I already solved it.
        As you proposed, the existence of the file by fopen,
        to get the original filetime of the file I had to access the HTTP-HEAD.

        I succeeded so:

        function filemtime_remot e($uri)
        {
        $uri = parse_url($uri) ;
        $handle = @fsockopen($uri['host'],80);
        if(!$handle)
        return 0;

        fputs($handle," GET $uri[path] HTTP/1.1\r\nHost: $uri[host]\r\n\r\n");
        $result = 0;
        while(!feof($ha ndle))
        {
        $line = fgets($handle,1 024);
        if(!trim($line) )
        break;

        $col = strpos($line,': ');
        if($col !== false)
        {
        $header = trim(substr($li ne,0,$col));
        $value = trim(substr($li ne,$col+1));
        if(strtolower($ header) == 'last-modified')
        {
        $result = strtotime($valu e);
        break;
        }
        }
        }
        fclose($handle) ;
        return $result;
        }

        I returns the original filetime as an Unix-timestamp.

        Greetings from the baltic sea

        Hanjo

        --
        Software & Seminar-Kontor Hans-Joachim Grüßner
        Glasholz
        D-24369 Waabs
        The premium domain gruessner.de is for sale on fruits.co. Secure the domain now and start your online success story. Safe payment and quick transfer are guaranteed.

        Comment

        Working...