Forums

PHP

This topic is locked

Creating text file

Posted 27 May 2003 20:20:51
1
has voted
27 May 2003 20:20:51 Saeed Abdi posted:
I'm trying to automate the way we configure routers and since 90% of the config file are usually the same I though this would be easy to achieve with php script and a simple form.

I created a form where teckies can enter IP addresses, ref-name and subnet etc, that form passes those details to a page that prints the whole config to the screen. Now I need to write that result to a new file where the file name is same as the ref-name, this is where my problem begins, What I have done so far is I put the hidden fields in the output page which hold the values that I need (config) and (refname), config holds the whole of the config file where ref-name only holds the ref-name, and what I need to do is pass this to a new script which will first check if file with the same name exists and if it does it will error (something like file exists please choose different ref-name) other wise it will create a file, can anyone help

This is the bit of code that creates the file but because my lack of php knowledge I'm not quit sure how to check with the "if" function and at the same time I would like to strip any HTM code before the file is saved.



<pre id=code><font face=courier size=2 id=code> &lt;? echo $_POST['refname'];

$filename = $HTTP_POST_VARS['refname'];

$handle= fopen($filename,'w');

// create the string
$config = $HTTP_POST_VARS['config'];

// write the string to the file handle
fputs($handle, $config);

// close the file
fclose($handle);
?&gt;

</font id=code></pre id=code>

Edited by - xlarge on 27 May 2003 20:26:40

Reply to this topic