Having an issue with fopen, etc

I’m having issues with getting the fopen code to create a file on my lighttpd server (running on my raspberry pi).

I used the very basic code of

fopen(‘testcof.txt’, ‘w+’);

to test making a file, and no file is created.

I’ve tried it from a client on my local network and also running the script in a browser on the raspberry pi. Neither have been successful in creating a txt file. Any thoughts or ideas?

Well, there can be hundreds of reasons this does not work. Often, it is either a permissions issue or the
file was locked as “busy”. The first thing I would try is to test it for regular writing, not opening as a zero
length file. Create a new page with this code in it. See if it writes the file. If not, we will need to add in
some error checking to see if the file is locked.
[php]
$fh = fopen($counter_file, ‘w’);
fwrite($fh, “Testing”);
fclose($fh);
[/php]
If it creates the file, all is good with your server and access to files… Step one…

Turn on error reporting when developing

[php]<?php

ini_set(‘display_errors’,1);
error_reporting(E_ALL);

fopen(‘testcof.txt’, ‘w+’);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service