Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-26-2004, 03:22 PM   PM User | #1
gsnedders
Senior Coder

 
gsnedders's Avatar
 
Join Date: Jan 2004
Posts: 2,340
Thanks: 1
Thanked 7 Times in 7 Posts
gsnedders will become famous soon enough
Creating Files

I have a form
Code:
    <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
PHP Code:
<?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
PHP Code:
echo ('<p class="error">File Already Exist</p>'
__________________
Geoffrey Sneddon

Last edited by gsnedders; 03-26-2004 at 08:02 PM..
gsnedders is offline   Reply With Quote
Old 03-27-2004, 06:21 AM   PM User | #2
l3vi
Regular Coder

 
Join Date: Jan 2003
Posts: 400
Thanks: 0
Thanked 0 Times in 0 Posts
l3vi is an unknown quantity at this point
Before you ask PHP questions, try and take a look at www.PHP.net
But... heres what you would need to do:
[code]
<?php
$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>";
exit;
}

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

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

fclose($handle);

} else {
echo "The file $filename is not writable";
}
}
?>
[\code]

Its that or something extremely close. 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 .
l3vi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:46 AM.


Advertisement
Log in to turn off these ads.