Jump to content

Generating files - fopen


Illasera

Recommended Posts

Hey all, 1.)I am trying to create a new file with fopen(filename, "w") (I have php 4.x.x.x, no 5, so Can`t use the new function "file_put_contents")(Mode = w : write only + create if not exist)2.)I have valid permission on the current directory that am trying to create the file in3.)I also wish for the file to be created with Encoded utf-8 without BOM4.)Please Note that am using both local/Remote servers to test the function, In this test i used local server to query php errors, But i have a remote storage server.5.)I am not sure about the syntax, lets say i have the following settings : (PLEASE NOTE THEY ARE FAKE!!!)host : ftp://80.122.144.82username : domain.compassword : XXX69XXXDSfilename : httpdocs/test.phpWhats the current syntax to place it within the fopen() function?Currently am using : $hostname = $user . ":" . $password . "@" . $host . "/" . $filename; fopen($hostname, "w")I get the following errors : Warning: fopen(domain.com:XXX69XXXDS@ftp://80.122.144.82/httpdocs/test.php) [function.fopen]: failed to open stream: operation failed in C:\xampp\htdocs\z_test.php on line 9if i add "ftp://" before the $host parameter, i get the following errors : Warning: fopen() [function.fopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\z_test.php on line 9Warning: fopen() [function.fopen]: connect() failed: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\z_test.php on line 9Thanks in advance.

Link to comment
Share on other sites

The manual page on the FTP wrapper suggests the following syntax:
$hostname = 'ftp://domain.com:XXX69XXXDS@80.122.144.82/httpdocs/test.php';fopen($hostname, "w")

Link to comment
Share on other sites

If your PHP file is encoded as UTF-8, then the written literals to the file will be encoded as UTF-8 with no BOM whether you want it or not.If the PHP file is not encoded as UTF-8, or you're getting the data from somewhere else (where it's not encoded as UTF-8), you'll have to do a charset convertion.To do any kind of charset convertions, you'll have to use iconv. To $in_charset specify the encoding of the literal you're passing, and specify "UTF-8" as $out_charset.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...