At 22:48 06.11.2002, Charles Wiltgen said:
>Well, I'm able to make an empty file with
>    fopen("ftp://username:password@;", "w")
>However, I'm still nowhere because this file belongs to the user and her
>group, not to Apache, so I still can't write to it.

Why don't you do it this way:

$fp = fopen("ftp://username:password@;", "w");
if ($fp) {
        // now write whatever you want to
        fwrite($fp, 'Some content', 12);
else die('Can\'t create target file');

I don't see a reason why you shouldn't directly use the file handle
returned by fopen - that's why the PHP god has created it :)

See this sample code how to achieve this (substitute any necessary data).
Note that when opening a file using the FTP protocol you cannot
truncate/replace an existing file, you need to delete it first (this is
dictated by the FTP protocol AFAIK).


// --- configure this
$user = '**user**';
$pass = '**pass**';
$ftphost = 'ftp_upload_host';
$wwwhost = 'webhost_to_test';
$ftpfile = '/www/sample.html';
$wwwfile = '/sample.html';
// -- end configure

$time = strftime('%D %T');
$link = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];

$x = <<<EOF
<meta http-equiv="Pragma" content="no-cache"> 
<meta http-equiv="Cache" content="none">
<title>**By PHP** $wwwhost$wwwfile **By PHP**</title>
<h1>Created by PHP via FTP</h1>
Creation time: $time<p>
<a href="$link">Test</a>


$fp = ftp_connect("$ftphost");
if ($fp) {
        $login = ftp_login ($fp, $user, $pass); 
        ftp_delete ($fp, $ftpfile); 
else die('Cannot connect to FTP');

$fp = fopen("ftp://$user:$pass@;$ftphost$ftpfile", 'w');
if ($fp) {
        fwrite($fp, $x, strlen($x));
        header("Location: http://$wwwhost$wwwfile";);
else die('Cannot create file via FTP');


   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to