[thelist] PHP fwrite anomaly

Sales @ Lycosa sales at lycosa.co.uk
Sat Oct 9 04:28:00 CDT 2010


Hi guys,

 

I am trying to write files to a remote server using PHP fwrite, but it
simply won't write the files.

The following test code works perfectly on my windows/apache/php/mysql
development machine, and creates the test.txt file with the words 'hello
world'.

When I run it from my Linux web server, it returns positive for the file
creation, and gives a resource id number. The file, however, has not been
created on the remote server, so the fwrite function fails.

Stuff I have checked already: I have been through PHP/Apache settings, set
suexec, opened firewall IP addresses, enabled allow_url_fopen

 

Because it works from my windows machine, I am confident the receiving
server has been set up correctly. Both are VPS servers that I can alter, and
are both running Linux CentOS with WHM/cPanel.

 

Any clues would be most welcome. Thanks, Phil

 

<?

$file_location = "ftp://username:password@server.com/public_html/test.txt";

 

echo "attempting to create file: $file_location";

$f = fopen("$file_location", "w");

if (!$f) echo ".. failed\n\n";

else echo ".. success ($f)\n\n";

 

echo "attempting to write data to file";

$data = "hello world";

$fwrit = fwrite($f, $data);

if (!$fwrit) echo "..failed";

else echo " ..success ($fwrit)";

 

fclose($f);

?>



More information about the thelist mailing list