PCTechTalkhttp://www.pctechtalk.com/forums/

Go Back   PCTechTalk > PC Tech > Web Related

Reply
 
LinkBack Thread Tools Display Modes
Old 02-29-2004, 05:41 PM   #1 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
create a file based on form input (php?)

Hi all,

im wanting to create a html file based on whats entered into a form

ive searched google for almost 2 days now and not found anything,
ive searched the php manual too but cant find any function there for creating html files..

...or maybe im just not good at searching :\

any help would be appreciated

thanks
-c0lin
Colin-uk is offline   Reply With Quote
Old 02-29-2004, 09:31 PM   #2 (permalink)
Registered User
 
Asterix's Avatar
 
Join Date: Sep 2002
Posts: 824
Asterix
Ok colin here are two cases for ur question and two solutions based on php:

U want to create a file on harddisk:
http://www.php.net/manual/en/function.fopen.php

Now if u want to send a html file as reply for form submission then,
http://www.php.net/manual/en/tutorial.forms.php
__________________
We all are practical in our interests but, idealist when it concerns others....

Last edited by Asterix; 02-29-2004 at 09:39 PM.
Asterix is offline   Reply With Quote
Old 03-01-2004, 06:16 AM   #3 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
Thanks for te reply asterix,

i know how to create a file with fopen()

but i dont know how to take the file name from a form entry..
Colin-uk is offline   Reply With Quote
Old 03-01-2004, 12:41 PM   #4 (permalink)
Registered User
 
Asterix's Avatar
 
Join Date: Sep 2002
Posts: 824
Asterix
well that..

u can do that like this say u have a form like this
Code:
<form action="act.php" method="GET">
<input type="text" name="file">
<input type"submit">
Then to get filename in act.php
Code:
<?php
echo $_GET["file"];
?>
__________________
We all are practical in our interests but, idealist when it concerns others....
Asterix is offline   Reply With Quote
Old 03-01-2004, 12:42 PM   #5 (permalink)
Registered User
 
Asterix's Avatar
 
Join Date: Sep 2002
Posts: 824
Asterix
or try this

http://www.php.net/manual/en/tutorial.forms.php
__________________
We all are practical in our interests but, idealist when it concerns others....
Asterix is offline   Reply With Quote
Old 03-01-2004, 01:29 PM   #6 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
why would you want to create a html file? isn't PHP meant to do that for you on-the-fly?
__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 03-01-2004, 03:57 PM   #7 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
thanks for the replys

i tried adding the $_GET["file"] to my existing php script like below:

PHP Code:
<?php

$server_path 
"./"//Path to log directory 
$log_entries $_POST['title']. "<br /><br />" .$_POST['comments']. "<br />" .$_POST['div']. "\n"
$fp fopen($server_path .$_GET['filename']. "a") or die("Error, Cannot create file."); 

if (
$fp!= false



fwrite($fp$log_entries); 
fclose($fp); 
print(
"done") or die("Error!");


?>
but i get this error:

Warning: fopen() expects at least 2 parameters, 1 given in /home/colinuk/public_html/test/add.php on line 5


whats wrong?
(its probably somthing obvious)

Last edited by c0lin; 03-01-2004 at 04:11 PM.
Colin-uk is offline   Reply With Quote
Old 03-01-2004, 05:50 PM   #8 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
hehe...
fopen($server_path .$_GET['filename']. "a")

the dot in front of "a" should be a comma (,), then it works...

However GET probably won't work here, use $_POST instead, but why not helping yourself and using $_REQUEST for all? ($_REQUEST is a union of $_GET and $_POST)
__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 03-02-2004, 03:46 PM   #9 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
it worked

as you can see im still gettin used to PHP, even a simple replacement of a dot with a comma confused me enough to post lol


thanks for the help
Colin-uk is offline   Reply With Quote
Old 03-02-2004, 04:24 PM   #10 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
all start with asking, so don't bother m8!
__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 03-02-2004, 04:51 PM   #11 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
well i got it to create the file...but now it wont write the other fields into it (title, comments and div) :\
Colin-uk is offline   Reply With Quote
Old 03-03-2004, 01:17 PM   #12 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
did you use $_REQUEST instead of $_POST ?
__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 03-03-2004, 01:19 PM   #13 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
nope
Colin-uk is offline   Reply With Quote
Old 03-03-2004, 03:30 PM   #14 (permalink)
Da House Nerd
 
greffov's Avatar
 
Join Date: Dec 1969
Location: One CPU Lane
Posts: 3,512
greffov will become famous soon enough
{hint}
__________________
Linux virusscanner detected a virus:
Windows 95 ... delete [Y/n] y
~
~

:wq
greffov is offline   Reply With Quote
Old 03-04-2004, 07:15 AM   #15 (permalink)
Registered User
 
Colin-uk's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 928
Colin-uk is on a distinguished road
i changed the form to submit with POST instead of GET and it workes perfectly now

thanks for all the help everyone, much appreciated
Colin-uk is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 07:03 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
2001 PCTechTalk