Jump to content

Recommended Posts

Posted

Im after a really simple php page, that will simply have a single text box, and a submit button, and basically just take the contents of the text box and append it to a file on the server...

 

Anyone able to knock something up for me please? :)

Posted
Im after a really simple php page, that will simply have a single text box, and a submit button, and basically just take the contents of the text box and append it to a file on the server...

 

Anyone able to knock something up for me please? :)

 

I have exactly what you need but its asp and runs on ISA

 

any good for you?

  • Thanks 1
Posted

asp would be alright if i could get asp working on apache..

 

also it needs to be plaintext on one line only as another script on the server is going to be reading the text file

Posted

Thanks for remind me why I hate ASP :)

 

In PHP...

 

if(isset($_POST['content'])){

$filename = 'foo.txt';
$fhandle = fopen($filename, 'a');
fwrite($fhandle, $_POST['content'] . "\n");
fclose($fhandle);
echo 'File has probaly been written.';

} else {
?>

</pre><form method="post">
	

	
</form><br><br>}<br

  • Thanks 1
Posted
Im after a really simple php page, that will simply have a single text box, and a submit button, and basically just take the contents of the text box and append it to a file on the server.

 

Will more than one person be using it at a time? Like a class of 30 children? If so, watch out for race conditions when writing files - one user gets a handle on a file, then another user, they both think they are writing to the same point in the file and one users' data gets lost. This is why most modern web development is done with databases, as they ensure sequential writing of data.

 

--

David Hicks

  • Thanks 1
Posted
Will more than one person be using it at a time? Like a class of 30 children? If so, watch out for race conditions when writing files - one user gets a handle on a file, then another user, they both think they are writing to the same point in the file and one users' data gets lost. This is why most modern web development is done with databases, as they ensure sequential writing of data.

 

--

David Hicks

 

I missed this post completely sorry.

 

Its only going to be a rarely used thing, and Ill be the only one using it.. thanks for the info though :)

Posted

Yep. This should work; but it depends largely on the server's configuration and if it has a mail transport agent installed (MTA).

 

$to = '[email protected]';
$subject = 'Web Form';
$body = "File appended with data:\n\n {$_POST['content']}";
$headers = 'From: Web Form ';
mail($to, $subject, $body, $headers);
?>

  • Thanks 1
Posted

I cant get the mail bit working but i think thats my sendmail not working more than anything...

 

Ive got it as this so far, but im looking to add one more function.. (I added in a bit to show what was in the file already.. probably crude/bad but it works heh)

 

if(isset($_POST['content'])){

       $filename = 'file.txt';
       $fhandle = fopen($filename, 'a');
       fwrite($fhandle, $_POST['content'] . "\n");
       fclose($fhandle);
       echo 'Added to file.';

} else {
?>


One Line Submission


Currently in file:
$file = "file.txt";
$f = fopen($file, "r");
while ( $line = fgets($f, 1000) ) {
print $line. "
";
}
?>

Enter your line
       </pre><form method="post">
               

               
       </form><br><br><br>}<br>?&g

 

What I would like to do, and I dont know if its possible, but after it writes the 'Added to file' text, to have a button, which when pressed would execute a script to run on the server... Is that even possible?

Posted
What I would like to do, and I dont know if its possible, but after it writes the 'Added to file' text, to have a button, which when pressed would execute a script to run on the server... Is that even possible?

 

Do you mean to just re-direct the browser to a separate page? Or do something without the user noticing?

Posted
Do you mean to just re-direct the browser to a separate page? Or do something without the user noticing?

 

I want it to display a link/button, which when clicked, executes a script on the server. Is there a function for this in php?

 

At the moment I have put the script into the servers cgi-bin folder, but when I click on it it just tries to send me the script as a download..

 

Its a python script if that makes any difference from what im trying to do..

 

edit: Ive just found this in google, is this what Im after?

 

shell_exec("python myscript.py"); 

Posted

Yes, if the web server is not configured to run Python scripts, then it will just offer it as a download. The shell_exec() would probably work, yes. But there are different methods for running external processes - it would be worth finding out which one is best for your needs. There's passthru(), exec() and system() available at your disposal.

 

PHP: Program execution - Manual

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...