How to create an attachment?

Discussion in 'JavaScript' started by lost, Oct 31, 2005.

  1. #1
    I have a textarea where the user can input notes about a certain product. After input, the user saves the form and the saved text should be stored as an attachment.
    How do i do this??
     
    lost, Oct 31, 2005 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you mean the text is emailed to somebody as an attachment?
     
    dave487, Nov 1, 2005 IP
  3. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    not emailed, but stored.
    The text is stored as an attachment and available to the user to open if needed...do you know what i mean?
     
    lost, Nov 1, 2005 IP
  4. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So you want to save it as a text file and allow the user to open it with a link like
    <a href="textfileabc.txt" target="_blank">Click to open your file</a>
    ????
     
    dave487, Nov 1, 2005 IP
  5. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Actually, thats a good idea...how would i do that??
     
    lost, Nov 1, 2005 IP
  6. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You would need sessions and a database to do this properly but the script below should get you started.

    You need to use a server side script eg php to do this, it can't be done using Javascript.

    $file = fopen("myTextFile.txt","w");
    fwrite($file,"This is where the contents of the text file goes");
    fclose($file);
    PHP:
    for more info see
    http://www.php.net/manual/en/function.fopen.php
     
    dave487, Nov 2, 2005 IP
  7. dtang4

    dtang4 Active Member

    Messages:
    303
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Just to elaborate.. you would also need to copy the uploaded file from the tmp directory to where you want it to be located. You should also rename the file accordingly.
     
    dtang4, Nov 3, 2005 IP
  8. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok, i have the text entered by the user written to a file. Now, how can i take that file and create a link to it and then display that link?
    Anyone??
     
    lost, Dec 21, 2005 IP
  9. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If you are creating the file in yoursite.com/files/file1.txt then you can just do a normal link to this fiile like you would to a web page.
     
    dave487, Dec 21, 2005 IP