2

I am trying to write to file on external server with php. I have the FTP details. Here is my code

$handle = fopen("ftp://USN:PASS@DOMAIN/FOLDER/FILE.HTML", "a");

fwrite($handle, "Some text");

fclose($handle);

upon execution I get "The connection was reset. The connection to the server was reset while the page was loading." error in browser. What am I doing wrong?

5
  • 1
    Are you getting any errors in your error log? Is that an error from the webpage or from the ftp request? Commented Apr 14, 2015 at 18:21
  • 1
    It is not form the FTP request. Is the code wrong? Commented Apr 14, 2015 at 18:44
  • You likely need to use the ftp functions. I don't believe fopen will "speak" the ftp protocol. If you can't use the ftp functions, then you would likely need to find (or write your own) object to handle it using fsockopen. Commented Apr 14, 2015 at 19:27
  • 1
    First check your logs, then be sure you have allow_url_fopen set as true in your php.ini or change it in execution mode with this code: ini_set("allow_url_fopen ", 1);. Commented Apr 14, 2015 at 19:37
  • 1
    I don't have access to my php.ini. I'm using 000webhost. Commented Apr 15, 2015 at 6:03

1 Answer 1

1

It works in my local server so this approach is absolutely possible. I guess 000webhost has set

ini_set("allow_url_fopen ", 0);

in php.ini

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.