Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing text file on server

Status
Not open for further replies.

merlinv

Programmer
Jun 11, 2001
32
0
0
US
I would like to write a text file to a server. Can't seem to make it work.

Code:
$c= "ftp://un:pw@mydomain.com//public_html/sd/test.txt"]
$filename = $c;
$fp = fopen( $filename, "r" ) or die("Couldn't open $filename");

where un = username and pw = password and sd = subdirectory
Seems to open for reading. When I change the "r" to "w" it seems not to work. I don't gea and error saying it can't open it but no file is created on website.

Suggestions?

thanks

Merlinv
 
this is simple file create tutorial:

$ourFileName = "testFile.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

cheers,
M.
 
Hi

Merlinv said:
I don't understand the following
Just as a consolation, neither I can get the meaning of lgarner's post.

According to FTP and FTPS your code is correct. ( Excepting the closing bracket ( ] ) used instead of semicolon ( ; ), but that must be a typo. )

I would say, the problem is with the FTP server's configuration. PHP only plays the role of an FTP client and asks the FTP server to do something. The server may or may not satisfy the request, depending on its capabilities and/or configuration. Additionally the FTP may behave badly and not inform the client about the denial/failure.

By the way, is possible that the FTP server creates the new file in a temporary directory and moves it to its final location only when the file is closed. That way it can check the file's content before accepting if certain MIME types or viruses should be rejected. So, have you [tt]fclose()[/tt]'d that file before checking for its existence ?

Feherke.
 
yes the ] is a typo in the real file it is ;

I have closed the file at the end of my test and the written
file is nowhere to be found. It also does not provide an error.

Very frustrating. Any more suggestions? Using the path
for reading works correctly.

Thanks again.

Merlinv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top