I'm working on a php application and when setting it up for the first time it writes a file (system_info.php) to the server that stores several details of the system it is being installed in.
If the server is not writable I would like to print this configuration on a text area and prompt the user to create the file system_info.php on the top level directory of this application on the server and paste the configuration in it.
How or what is the best way to test if the server is writable?

Thanks

sureronald

Recommended Answers

All 3 Replies

If you mean weather you can write to a file using php then the following should be able to test that:

<?
file_put_contents('test.txt','The server is writable.');
echo file_get_contents('test.txt');
?>

I am using the php touch function to create the file and then open and write into it with the regular file operation functions.
The problem is that the touch function fails if the server is not writable especially on GNU/Linux.

If you mean modifying the same text file a few billion times in a loop and the file gets damaged then I believe that is the same with windows servers and possibly all servers. Point is that on occasion there is the unexpected error which can really mess things up. That is why I find it's best to have lots of little files or databases.

However, to test this bug of yours, try the following script:

<?
file_put_contents('test.txt','The server is writable.');
if (file_get_contents('test.txt')!==false) {
echo 'The server can read files<br>';
} else {
echo 'There was an error reading a php generated text file.<br>';
}
if(touch ('test.txt')) {
echo 'The server can use the touch function on text files';
} else {
echo 'There was an error using the touch function on a text file';
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.