Page 1 of 1

writing a text file on server

Posted: Wed Apr 15, 2009 1:21 pm
by merleore
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I have been trying to write a text file to a server.

Code: Select all

$File = "ftp://username:password@the-ace-of-clubs.com//public_html/testwrt/example.txt"; 
$Handle = fopen( $File, "w" ) or die("Couldn't open $file");
 
$Data = "Jane Doe\n"; 
echo " data >$Data<- <br>";
fwrite($Handle, $Data); 
$Data = "Bilbo Jones\n"; 
echo " data >$Data<- <br>";
fwrite($Handle, $Data); 
fclose($Handle);

It does not return and error or say that the file couldn't be opened. Yet it does not appear on the server.

suggestions ?

thanks.

Merleore


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: writing a text file on server

Posted: Wed Apr 15, 2009 2:12 pm
by McInfo
Put this at the top of your script:

Code: Select all

error_reporting(E_ALL);
Edit: This post was recovered from search engine cache.

Re: writing a text file on server

Posted: Wed Apr 15, 2009 2:38 pm
by merleore
ok I did that and no error was reported and still no text file.

thanks for your input.

Could use other suggestions on how to get it to work.

Merleore

Re: writing a text file on server

Posted: Wed Apr 15, 2009 2:58 pm
by McInfo
It could be the double slashes:
ftp://username:password@the-ace-of-clubs.com//public_html/testwrt/example.txt
You can test that you can read the file with this script:

Code: Select all

<?php
error_reporting(E_ALL);
$file = 'ftp://username:password@the-ace-of-clubs.com//public_html/testwrt/example.txt';
header('Content-Type: text/plain');
echo '{BEGIN}';
echo file_get_contents($file);
echo '{END}';
?>
Edit: This post was recovered from search engine cache.

Re: writing a text file on server

Posted: Wed Apr 15, 2009 4:57 pm
by merleore
I have already proved I can read the text file - I just have a problem writing one.

Everything appears to work ok but nothing appears on the server. I have checked to see if I can write to server and
everything I see says yes.

Thanks - still looking for solution

Merleore

Re: writing a text file on server

Posted: Wed Apr 15, 2009 7:09 pm
by McInfo
Well, I learned something new today! It is not easy to wade through the documentation on stream contexts to get just what you need.

Try this:

Code: Select all

<?php
error_reporting(E_ALL);
$link = 'the-ace-of-clubs.com//public_html/testwrt/example.txt';
$file = 'ftp://username:password@'.$link;
echo 'Starting insertion... ';
$stream_options = array('ftp' => array('overwrite' => true));
$stream_context = stream_context_create($stream_options);
if ($fh = fopen($file, 'w', 0, $stream_context))
{
    fputs($fh, 'Insertion string');
    fclose($fh);
}
else
{
    die('Could not open file.');
}
echo 'Insertion complete: ';
echo '<a href="http://'.$link.'">http://'.$link.'</a>';
?>
Edit: This post was recovered from search engine cache.

Re: writing a text file on server

Posted: Fri Apr 17, 2009 11:09 am
by merleore
thanks for the reply.

I tried the code listed 2 different ways. Using what you had and then removing "public_html" in the call list .

Either way it did not work. I still do not get an error but no text file appears on the website.

Still looking .

Thanks.

Merleore