Log in

View Full Version : Edit .txt file on server



mburt
10-15-2006, 04:06 PM
I know you can edit text files with ActiveX on your comp., but I'm wondering if this can be done on a server (FTP). I completely threw away the idea of a MySql database, so I'm trying to find an alternate route. Thanks

jscheuer1
10-15-2006, 04:22 PM
Using FTP, I've always just edited the file then uploaded it. You can open and do relatively simple operations to text files and close them using asp. With a little creativity, this could be 'editing'. PHP includes the same basic, if not more, functionality in this regard, as far as I know (not much experience with PHP or asp but, I have messed with text files using asp and it works.

mburt
10-15-2006, 07:06 PM
I want the user to be able to do it -- to have a page where the user can do it dynamically. I understand what you're saying though, and thanks.

mburt
10-15-2006, 07:12 PM
My server won't let me use asp though, so I'll have to look into PHP.

Twey
10-15-2006, 08:41 PM
There's no need to use FTP. A script on the server will (presumably) be running as the user to whom the file belongs, and so will have read and write access to it.

jscheuer1
10-15-2006, 08:47 PM
In your last thread on this topic I mentioned a free PHP add-on that allows editing and more. From what it says on the info page, you can control who gets to edit and what files are available to edit. Here is the URL again:

http://www.phpxplorer.org/phpXplorer/webIndex.php

I'm not recommending this, haven't used it but, looks promising and it is free.

I'm sure it must be possible to work out a simple editor by importing the text of a text file to a textarea, editing it there, and then submitting it to a page that would then write the new value to the same text file (perhaps, if need be, deleting the old version first). The program I mention above is much more involved but, presumably they have already worked out most of the details. It may require access to the server to install it though.

mburt
10-16-2006, 03:00 PM
Yeah. I saw that, but I couldn't get it to work. I posted my question this time, in a different way to try to get some different answers.

mburt
10-16-2006, 05:24 PM
Argh... My webhost disabled system() and exec() commands in PHP. So I can't even do that. This is horrible. Are there any alternatives to system() ?
This is the dos line I used:

echo test > test.txt

djr33
10-16-2006, 08:05 PM
try fopen()

if that fails, then you likely won't be able to do anything with files.

But, if it works, then you can open the file into a variable and edit it all you want, then use fwrite() to save it.

mburt
10-16-2006, 08:33 PM
Okay. Thanks djr33

mburt
10-16-2006, 08:40 PM
Thanks alot djr33! I got this to work *sigh of relief. Again, thanks alot :D

mburt
10-16-2006, 09:07 PM
Tiny problem: The following won't display the contents of the .txt file:


<?php
$fc = file("file.txt");
echo $fc;
?>

It returns the value "Array" for some reason...

Twey
10-16-2006, 09:45 PM
That's because it's an array of all the lines in the file. See the documentation for file (http://www.php.net/file)(). You probably mean file_get_contents (http://www.php.net/file-get-contents)().

mburt
10-16-2006, 10:15 PM
file_get_contents() doesn't put in escape characters :(

I have \n written in the file to make a line, and it all appears as one string. How can this be fixed?

mburt
10-16-2006, 10:34 PM
Okay. (sorry for all the posting :)) But it's done; it is a fully-functional comments page without a MySql database.
http://mburt.mb.funpic.org/contact.php
Fire at will :)

Twey
10-17-2006, 04:49 PM
I have \n written in the file to make a line, and it all appears as one string. How can this be fixed?That's not what's happening at all. Remember, you're outputting HTML. In HTML, linebreaks are treated as a space.

mburt
10-17-2006, 07:29 PM
Yeah, I forgot. Kind of a stupid mistake. I changed my mind and made the file a .htm document so html tags could be valid in my code, but I used strip_tags() to make sure the user couldn't use html.

the-disturbed
10-18-2006, 11:48 PM
link's broken lol

mburt
10-19-2006, 12:39 AM
Okay... here's the new link :):

http://mburt.mb.funpic.org/guestbook.php