Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    264
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Making TXT files downloadable

    How do I go about making my txt files download instead of open in a new window/tab?

  • #2
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    Not sure what you mean. How about some examples or better still a link?

    Frank
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by IFeelYourPain View Post
    How do I go about making my txt files download instead of open in a new window/tab?
    You could add a statement in your .htaccess file, to forcibly prompt for download the file, like
    Code:
    AddType application/octet-stream .txt
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    IFeelYourPain (05-09-2009)

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Posts
    264
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    You could add a statement in your .htaccess file, to forcibly prompt for download the file, like
    Code:
    AddType application/octet-stream .txt
    That's exactly what I was looking for thanks man!

    ALSO: If I include a text file with php will your code force the text file to download instead of including itself within a document.

    Quote Originally Posted by effpeetee View Post
    Not sure what you mean. How about some examples or better still a link?

    Frank
    abduraooft knew what I was talking about without any examples. However to further explain his code it forces the text file to download instead of displaying the text file in a new tab/window.

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    ALSO: If I include a text file with php will your code force the text file to download instead of including itself within a document.
    How about having a try?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Regular Coder
    Join Date
    Sep 2007
    Posts
    264
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    How about having a try?
    Yea it works only one little issue.

    Instead of line breaks it replaces them with little square boxes.

    EX:
    http://www.consolediscussions.com/fo...ULUS-10251.txt

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by IFeelYourPain View Post
    Yea it works only one little issue.

    Instead of line breaks it replaces them with little square boxes.

    EX:
    http://www.consolediscussions.com/fo...ULUS-10251.txt
    Sorry, I don't get your current issue.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    Regular Coder
    Join Date
    Sep 2007
    Posts
    264
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Sorry, I don't get your current issue.
    If you download the TEXT file, it won't put it in the format I uploaded it to the server.

    Instead of:
    This
    Code
    Is
    Cool

    It shows as:
    This[]Code[]Is[]Cool

    How can I prevent this?

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    It has the line breaks when opened in notepad++. Not sure why notepad behaves like that.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #10
    Regular Coder
    Join Date
    Sep 2007
    Posts
    264
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    It has the line breaks when opened in notepad++. Not sure why notepad behaves like that.
    Is there a way to fix it, because I am sure many of my members will complain.

  • #11
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Personally I don't think its a good idea having your users download all those text files. Would annoy the hell out of me having lots of text files all over the desktop. If you can't manage to get the popups working then you could always go for getting the files to open in a new tab/window with target="_blank"

    Code:
    <a href="/Files/A/Annoying.txt" target="_blank">View</a>
    Another thing to consider is what program is opening the text files. For instance notepad will be looking for an ascii r\n (carriage return and newline) while other programs might except just \n or \r. Different programs expect different end of line character combinations. However if it opens a text file in a browser you see the newlines as they were formatted.

    http://cybadev.co.uk/example.txt

    Edit:
    P.S look at the source to the above link that is an example of a target="_blank" anchor
    Last edited by timgolding; 05-16-2009 at 01:29 PM.
    You can not say you know how to do something, until you can teach it to someone else.

  • #12
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Would annoy the hell out of me having lots of text files all over the desktop.
    It's up to the user to decide the location to which the file to be saved.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #13
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by abduraooft View Post
    It's up to the user to decide the location to which the file to be saved.
    Yeah i know but considering what IFeelYourPain is trying to do which is not fully stated in this thread. Look at this thread for a clearer idea.

    http://www.codingforums.com/showthread.php?t=165918

    I don't see that making these popups download links is the way to go.
    You can not say you know how to do something, until you can teach it to someone else.

  • #14
    Regular Coder
    Join Date
    Sep 2007
    Posts
    264
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by timgolding View Post
    Yeah i know but considering what IFeelYourPain is trying to do which is not fully stated in this thread. Look at this thread for a clearer idea.

    http://www.codingforums.com/showthread.php?t=165918

    I don't see that making these popups download links is the way to go.
    Your mixing up my features lol. The popups are to preview the text files and the download feature is actually to download. I guess it would be best to show you a live demo:
    http://www.consolediscussions.com/forum/codes.php

    The popups will actually be used to load the text file into an Ajax popup which will then format the text so that it previews.
    Last edited by IFeelYourPain; 05-16-2009 at 06:46 PM.

  • #15
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Ah ok my apologies. Seems like you got it the downloads working? Where are the popups?
    You can not say you know how to do something, until you can teach it to someone else.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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