View Full Version : Creating Files

03-26-2004, 04:22 PM
I have a form
<form action="" method="">File name:
<input name="filename" type="text" size="30" maxlength="47" />
<br />
<input name="name" type="submit" value="Submit" />
</form>I want to have a script which checks if [whatever they put in the form].php exists in /, if it doesn't, then I want it to create a file in / called [whatever they put in the form].php and a file in /files called [whatever they put in the form].txt, then put in /[whatever they put in the form].php

require ('files/topheader.txt');
require ('files/header.txt');
require ('files/[whatever they put in the form]');
require ('files/footer.txt');
require ('files/bottomfooter.txt');


If the file already exists I want the script to
echo ('<p class="error">File Already Exist</p>')

03-27-2004, 07:21 AM
Before you ask PHP questions, try and take a look at www.PHP.net
But... heres what you would need to do:
$filename = $_(post/get)[(whatever they put in the form)] . ".php";

if (file_exists($filename)) {
echo "<p class=\"error\">File Already Exist</p>";
} else {
if (!$handle = fopen($filename, 'a')) {
echo "<p class=\"error\">There was an error</p>";

// Write $somecontent to our opened file.
if (fwrite($filename, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";

echo "Success, wrote ($somecontent) to file ($filename)";


} else {
echo "The file $filename is not writable";

Its that or something extremely close. :D That script I just gave you does not write the .txt file just so you know. This is just a vague idea of what you need to write. Visit www.php.net and read some of the documentation. Its a great php learning thing. Also try and buy a few reference manuals (books on PHP) off of www.half.com .

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum