Hello, My host does not allow fopen,fwrite... functions, so what's the best alternative way to write to text files with PHP? Can I use cURL to write to files?
cURL can write to files, but it needs fopen() as well. (example) But you cannot write normal content from a variable or string.
OK, I've tried the following but it's not working. Could someone please tell me how to get it working. I want cURL to read text from a variable and then store it into a .txt file. Here's my failed try (It says can't resolve host, but I want it to read from a string not a URL): $string = "Append this text to the file named target_file.txt\r\n"; $opts = array( 'http' => array('method'=>'GET','header'=>'status: HTTP/1.1 200 OK\r\n','content' => $string) ); $context_resource = stream_context_create($opts); // Try to simulate a server response $curl = curl_init(); $fp = fopen("target_file.txt", 'a'); // This is the file to which I want to append the text in $string curl_setopt ($curl, CURLOPT_URL, $context_resource); curl_setopt($curl, CURLOPT_FILE, $fp); //Store output in $fp curl_exec ($curl); if (curl_errno($curl)) { echo curl_error($curl); } curl_close ($curl); PHP: