+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
Web Development Thread, read from text box, append to file in Coding and Web Development; webman, that works a treat.. thanks heaps...
  1. #16

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    webman, that works a treat.. thanks heaps

  2. #17

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324
    You're welcome.

  3. Thanks to webman from:

    RabbieBurns (16th October 2009)

  4. #18

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    Quote Originally Posted by dhicks View Post
    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

  5. #19

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    webman, do you happen to have a mail function that I could add to that that would email using a smtp the string that was entered to a certain email address?

  6. #20

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324
    Yep. This should work; but it depends largely on the server's configuration and if it has a mail transport agent installed (MTA).

    Code:
    <?php
    $to = 'you@example.com';
    $subject = 'Web Form';
    $body = "File appended with data:\n\n {$_POST['content']}";
    $headers = 'From: Web Form <webform@example.com>';
    mail($to, $subject, $body, $headers);
    ?>

  7. Thanks to webman from:

    RabbieBurns (16th October 2009)

  8. #21

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    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)

    Code:
    <?php
    
    if(isset($_POST['content'])){
    
            $filename = 'file.txt';
            $fhandle = fopen($filename, 'a');
            fwrite($fhandle, $_POST['content'] . "\n");
            fclose($fhandle);
            echo 'Added to file.';
    
    } else {
    ?>
    <html>
    <head>
    <title>One Line Submission</title>
    </head>
    <body>
    <h4>Currently in file:</h4>
    <?php
    $file = "file.txt";
    $f = fopen($file, "r");
    while ( $line = fgets($f, 1000) ) {
    print $line. "<BR>";
    }
    ?>
    
    <h4>Enter your line</h4>
            <form method="post">
                    <textarea name="content" rows="1" cols="50"></textarea><br />
                    <input type="submit" value="Save">
            </form>
    </body>
    </html>
    <?php
    }
    ?>
    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?

  9. #22

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324
    Quote Originally Posted by RabbieBurns View Post
    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?

  10. #23

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    Quote Originally Posted by webman View Post
    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?

    Code:
     shell_exec("python myscript.py");

  11. #24

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,406
    Thank Post
    640
    Thanked 961 Times in 661 Posts
    Blog Entries
    2
    Rep Power
    324
    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

SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Limit the number of characters in text box
    By MattCowen in forum Office Software
    Replies: 1
    Last Post: 21st September 2009, 04:57 PM
  2. edit/text box zoom utility
    By ajbritton in forum Windows
    Replies: 0
    Last Post: 13th February 2009, 11:26 AM
  3. Centering a scrolling text box in HTML
    By PWaite in forum Web Development
    Replies: 15
    Last Post: 19th January 2009, 09:53 AM
  4. EARTHQUAKE: READ TEXT FIRST, IT REALLY PUTS LIFE IN PERSPECTIVE
    By mattx in forum Jokes/Interweb Things
    Replies: 10
    Last Post: 28th February 2008, 09:46 AM
  5. Replies: 14
    Last Post: 12th September 2007, 10:13 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •