Uploaded .txt Files With No Carriage Return |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Zymic Free Web Hosting Zymic Free Web Hosting - General Discussion & Help |
||
![]() |
Uploaded .txt Files With No Carriage Return |
||
Mar 29 2010, 07:02 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 14 Joined: 28-March 10 Member No.: 136,360 |
Hello, whenever I upload a .txt file to my site for users to download, the downloaded version always has a line feed but no carriage return, so when opened in Notepad rather than each line being on a new line, they are seperated by a small square used to represent the line feed. Does anybody know what could be causing this?
|
|
|
Mar 30 2010, 02:36 AM
Post
#2
|
|
![]() Super Duper Ninja ![]() Group: Community Helper Posts: 484 Joined: 23-December 07 From: USA Member No.: 5,477 |
what are you using the upload this file, and program are you using to make this file?
|
|
|
Mar 30 2010, 11:26 AM
Post
#3
|
|
![]() Outrageously Uber Ninja ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Moderators Posts: 5,140 Joined: 11-May 08 From: Australia Member No.: 25,876 |
Due to .txt files being plain text files, no form of formatting is processed via the browser (line breaks, etc) . If you need to have formatting, I recommend HTML/XML for the feed. That way, you can use formatting and get your desired outcome.
|
|
|
Mar 30 2010, 12:53 PM
Post
#4
|
|
|
Newbie ![]() Group: Members Posts: 14 Joined: 28-March 10 Member No.: 136,360 |
what are you using the upload this file, and program are you using to make this file? FlashFXP to upload it, Microsoft Notepad to create it. Due to .txt files being plain text files, no form of formatting is processed via the browser (line breaks, etc) . If you need to have formatting, I recommend HTML/XML for the feed. That way, you can use formatting and get your desired outcome. Thanks for the info but the text file isn't being processed by the browser like that, it just gets directly downloaded to the users system, then upon the user running it in Notepad, rather than the proper Windows carriage returns and line feeds, it just seems to have the UNIX line feeds. The reason I want this is because I've written a few mIRC snippets/addons that i'd like people to be able to download, and seeing as my .mrc files were being rejected I had to rename them to .txt |
|
|
Mar 31 2010, 10:47 AM
Post
#5
|
|
|
Newbie ![]() Group: Members Posts: 14 Joined: 28-March 10 Member No.: 136,360 |
anybody?
|
|
|
Mar 31 2010, 12:39 PM
Post
#6
|
|
|
Member ![]() ![]() Group: Members Posts: 33 Joined: 23-November 09 Member No.: 119,662 |
Microsoft Notepad to create it. Use Pro Notepad like http://notepad-plus.sourceforge.net/uk/site.htm Because Microsoft Notepad displays incorrectly |
|
|
Mar 31 2010, 06:30 PM
Post
#7
|
|
|
Newbie ![]() Group: Members Posts: 14 Joined: 28-March 10 Member No.: 136,360 |
Use Pro Notepad like http://notepad-plus.sourceforge.net/uk/site.htm Because Microsoft Notepad displays incorrectly I already use Notepad++, viewing the files myself is not a problem. The problem is getting anyone who downloads the text file to also download extra software just to view it. Not very user-friendly, especially for a simple .txt file. I think the only workaround is to dynamically make some sort of duplicate in PHP with the proper \r\n for Windows, then serve that to the user rather than the original. Seems like a lot of hassle just for a text file though |
|
|
Apr 1 2010, 10:14 AM
Post
#8
|
|
![]() Outrageously Uber Ninja ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Moderators Posts: 5,140 Joined: 11-May 08 From: Australia Member No.: 25,876 |
Have you tried changing your encoding to something more widely accepted by systems?
|
|
|
Apr 1 2010, 01:55 PM
Post
#9
|
|
|
Newbie ![]() Group: Members Posts: 14 Joined: 28-March 10 Member No.: 136,360 |
Have you tried changing your encoding to something more widely accepted by systems? Yea I did try uploading it in different encodings, but the server serves it as UNIX regardless, it's like there's some kind of conversion when uploaded because the file sizes become smaller, presumably because the carriage returns are stripped. One thing that may be of note is when the files are downloaded via FlashFXP they are back in the proper encoding, but I think that's just because the software converts it back for me |
|
|
Apr 2 2010, 12:17 PM
Post
#10
|
|
|
Newbie ![]() Group: Members Posts: 14 Joined: 28-March 10 Member No.: 136,360 |
OK thanks for the ideas guys, I've come to a solution. See, when the .txt file is uploaded to the server, the server automatically strips every carriage return from the file.
So I wrote a small PHP script which takes a text file as input and creates a new text file with the proper carriage returns and line feeds for Windows systems. If anybody else would like to use it, here: CODE <?php if (isset($_POST["old"]) && isset($_POST["new"])) { if ($_POST["old"] == "" || $_POST["new"] == "") { print "Error: Parameters Missing"; exit; } $nfile = $_POST["new"] $ofile = $_POST["old"]; $lines = file($ofile, FILE_IGNORE_NEW_LINES); if ($fhandle = @fopen($nfile, "w")) { foreach ($lines as $line_num => $line) { fwrite($fhandle, $line . "\r\n"); } print "Successfully converted " . basename($ofile) . " to Windows encoding <br />"; print "<a href=\"" . $nfile . "\">Download " . basename($nfile); } else { print "Failed to open file stream. Did you set permissions for writing?"; exit; } } else { ?> <h2>Unix to Windows .txt Converter</h2> <h5>Directory permissions must be set to allow writing by the group</h5> <form action="" method="post"> <b>Original File:</b> <input type="text" name="old" /> <p><b>New File:</b> <input type="text" name="new" /> </p> <input type="submit" value="Submit" /> </form> <? } ?> Note: You must set writing permissions for the group on the directory you're working on. Also, you should place the file you save this as in the directory you're working on |
|
|
Jun 11 2011, 09:52 PM
Post
#11
|
|
|
Newbie ![]() Group: Members Posts: 2 Joined: 12-April 08 Member No.: 18,874 |
I had the exact same problem and managed to get around it simply by changing the extension of the file (for example, "test.txt" became "test.data") before uploading it. After that, I restored the extension of the uploaded file, and the contents were left untouched. Aside from the issue concerning the carriage returns, this method also prevents other modifications from being made, such as the removal of blank lines at the beginning or the end of a document. Compressing the file is another viable option.
|
|
|
![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 19th May 2013 - 11:31 PM |