----- Original Message -----
From: "Petre Agenbag" <[EMAIL PROTECTED]>
To: "Erwin" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, November 05, 2002 8:24 PM
Subject: Re: [PHP] Re: creating and ftp text file


> Hi Erwin
>
> OK, my first problem:
>
> your code genrates errors,
> it says fwrite and fclose are invalid file descriptors.

Errors or warnings? Probably the fopen function failes...

Add the following code:

<?
$fp = fopen( 'ftp://ftp.domain.com/file.txt', 'w' );
if ( !$fp )
  die( "Cannot open file\n" );
?>

You can then see if the fopen failes. If it does, then check the rights for
this user at the FTP Server.

> I gathered thatit is possibly because thos are for "normal" files, so I
> looked in the manual and found the FTP-functions, but it takes a
> $local_file variable, and that must be the name of the local file on
> disk, so I cannot simply put $content in there...

That's true for the FTP functions indeed, but you CAN use the normal file
function to...take a look at fopen in the manual. You can take a look at
example 1.

> Any ideas on how to directly stream the variable to the ftp site?

The only possibility to do this, is using fopen. If you can't use fopen for
some reason (i.e. don't give anonymous users write access to your FTP
Server), then you have to use the FTP functions:

<?
$query = 'select number from table where group=1';
$result = mysql_query( $query );

$content = '';
while ( $res = mysql_fetch_array( $result ) )
{
    $content .= 'Cellphone: ' . $res['number'] . "\n";
}
$content .= 'Reference: ' . $reference . "\n";
$content .= 'Notify: ' . $notify . "\n";

$name = tempnam( "/tmp", "" );
$fp = fopen( $name, "w" );
fwrite( $fp, $content );
fclose( $fp );

$ftp = ftp_connect( "ftp.domain.com" );
ftp_login( $ftp, "username", "password" );
ftp_put( $ftp, "filename", $name, FTP_ASCII );

unlink( $name );
?>

For this to work, you'll have to compile PHP with the --with-ftp
directive!!!

But again, I'm pretty sure the first possibility should work also.

Regards,
Erwin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to