Re: [PHP] Re: creating and ftp text file

2002-11-05 Thread Erwin Bovendeur

- 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:

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:



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




Re: [PHP] Re: creating and ftp text file

2002-11-05 Thread Petre Agenbag
Hi Erwin

OK, my first problem:

your code genrates errors, 
it says fwrite and fclose are invalid file descriptors.

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...
Any ideas on how to directly stream the variable to the ftp site?

Thanks
On Tue, 2002-11-05 at 17:09, Erwin wrote:
> > I am pretty up to standard with getting stuff into and out of mysql,
> > so I am basically just in need of pointers with generating the text
> > file and ftp'ing automatically.
> > It would be an even greater plus if it wasn't actually necessary to
> > create a physical text file on the hard drive, but to simply ftp the
> > "memory" file via the ftp functions, but I don't think that is
> > possible?
> 
> In fact, it is...just open the file on the ftp directly
> 
>  $fp = fopen( 'ftp://ftp.domain.com/file.txt', 'w' );
> ?>
> 
> You can then write directly to that filepointer:
> 
>  fwrite( $fp, 'some text' );
> ?>
> 
> Don't forget to close the file (I think PHP does that anyway, but it's nicer
> if you do that)
> 
>  fclose( $fp );
> ?>
> 
> >
> > My routine will already have connections to the db, and the query will
> > have already been run
> > (something like select number from table where group=1)
> > and I would then have a while to step through the result set.
> > This is where I need help, how to "create" the file and add the
> > numbers and "static" text to the file, and once completed with the
> > loop, to ftp to a server with username and password.
> 
> You'll have to loop trough the resultset
> 
>  $query = 'select number from table where group=1';
> $result = mysql_query( $query );
> 
> $content = '';
> while ( $res = mysql_fetch_array( $result ) )   // This piece of code will
> add all the Cellphone-numbers to the $content variable
> {
> $content .= 'Cellphone: ' . $res['number'] . "\n";
> }
> $content .= 'Reference: ' . $reference . "\n";
> $content .= 'Notify: ' . $notify . "\n";
> 
> // And add everything else to the $content variable which needs to be
> written
> 
> $fp = fopen('ftp://ftp.domain.com', 'w' );
> fwrite( $fp, $content );
> fclose( $fp );
> ?>
> 
> HTH
> Erwin
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


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




Re: [PHP] Re: creating and ftp text file

2002-11-05 Thread Petre Agenbag
Erwin
Thanks a million.
That's actually much simpler than I thought it would be...

I'm gonna give it a go just now, but I'm sure it will work!

Thanks again!


On Tue, 2002-11-05 at 17:09, Erwin wrote:
> > I am pretty up to standard with getting stuff into and out of mysql,
> > so I am basically just in need of pointers with generating the text
> > file and ftp'ing automatically.
> > It would be an even greater plus if it wasn't actually necessary to
> > create a physical text file on the hard drive, but to simply ftp the
> > "memory" file via the ftp functions, but I don't think that is
> > possible?
> 
> In fact, it is...just open the file on the ftp directly
> 
>  $fp = fopen( 'ftp://ftp.domain.com/file.txt', 'w' );
> ?>
> 
> You can then write directly to that filepointer:
> 
>  fwrite( $fp, 'some text' );
> ?>
> 
> Don't forget to close the file (I think PHP does that anyway, but it's nicer
> if you do that)
> 
>  fclose( $fp );
> ?>
> 
> >
> > My routine will already have connections to the db, and the query will
> > have already been run
> > (something like select number from table where group=1)
> > and I would then have a while to step through the result set.
> > This is where I need help, how to "create" the file and add the
> > numbers and "static" text to the file, and once completed with the
> > loop, to ftp to a server with username and password.
> 
> You'll have to loop trough the resultset
> 
>  $query = 'select number from table where group=1';
> $result = mysql_query( $query );
> 
> $content = '';
> while ( $res = mysql_fetch_array( $result ) )   // This piece of code will
> add all the Cellphone-numbers to the $content variable
> {
> $content .= 'Cellphone: ' . $res['number'] . "\n";
> }
> $content .= 'Reference: ' . $reference . "\n";
> $content .= 'Notify: ' . $notify . "\n";
> 
> // And add everything else to the $content variable which needs to be
> written
> 
> $fp = fopen('ftp://ftp.domain.com', 'w' );
> fwrite( $fp, $content );
> fclose( $fp );
> ?>
> 
> HTH
> Erwin
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


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




[PHP] Re: creating and ftp text file

2002-11-05 Thread Erwin
> I am pretty up to standard with getting stuff into and out of mysql,
> so I am basically just in need of pointers with generating the text
> file and ftp'ing automatically.
> It would be an even greater plus if it wasn't actually necessary to
> create a physical text file on the hard drive, but to simply ftp the
> "memory" file via the ftp functions, but I don't think that is
> possible?

In fact, it is...just open the file on the ftp directly

ftp://ftp.domain.com/file.txt', 'w' );
?>

You can then write directly to that filepointer:



Don't forget to close the file (I think PHP does that anyway, but it's nicer
if you do that)



>
> My routine will already have connections to the db, and the query will
> have already been run
> (something like select number from table where group=1)
> and I would then have a while to step through the result set.
> This is where I need help, how to "create" the file and add the
> numbers and "static" text to the file, and once completed with the
> loop, to ftp to a server with username and password.

You'll have to loop trough the resultset

ftp://ftp.domain.com', 'w' );
fwrite( $fp, $content );
fclose( $fp );
?>

HTH
Erwin


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