PHP Script to save text box content and generate random file name?

Discussion in 'PHP' started by harryjg, Aug 30, 2009.

  1. #1
    I think the title pretty much explains it.

    Is there a PHP script out there that will let me create a .txt file with a random filename, then save the data from a text box form to it?

    I have a slight feeling I may be asking for too much.

    But if you can help, that'd be great.

    Thanks.
     
    harryjg, Aug 30, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    One line:

    
    file_put_contents('writabledir/' . md5(time() + mt_rand()) . '.txt', $_POST['text']);
    
    PHP:
     
    premiumscripts, Aug 30, 2009 IP
  3. pneulameiro

    pneulameiro Peon

    Messages:
    440
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This indeed is a very good solution premium!. But I wonder why you need to do this. And you still have the rare event of file name collision.
     
    pneulameiro, Aug 31, 2009 IP