Connecting Tech Pros Worldwide Forums | Help | Site Map

Date and Filetime of a HTTP-File

Hanjo Grüßner
Guest
 
Posts: n/a
#1: Sep 28 '05
Hello,

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

$upload = ftp_put($conn_id, "$destination_file", "$source_file",
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
http://www.gruessner.de

Kirsten
Guest
 
Posts: n/a
#2: Sep 28 '05

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.php.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
alex
Guest
 
Posts: n/a
#3: Sep 28 '05

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


Hanjo Grüßner
Guest
 
Posts: n/a
#4: Sep 28 '05

re: Date and Filetime of a HTTP-File


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

[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_remote($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($handle))
{
$line = fgets($handle,1024);
if(!trim($line))
break;

$col = strpos($line,':');
if($col !== false)
{
$header = trim(substr($line,0,$col));
$value = trim(substr($line,$col+1));
if(strtolower($header) == 'last-modified')
{
$result = strtotime($value);
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
http://www.gruessner.de
Closed Thread