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
Printable View
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
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.
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.
My server won't let me use asp though, so I'll have to look into PHP.
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.
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.
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.
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:
Code:echo test > test.txt
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.
Okay. Thanks djr33
Thanks alot djr33! I got this to work *sigh of relief. Again, thanks alot :D
Tiny problem: The following won't display the contents of the .txt file:
It returns the value "Array" for some reason...Code:<?php
$fc = file("file.txt");
echo $fc;
?>
That's because it's an array of all the lines in the file. See the documentation for file(). You probably mean file_get_contents().
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?
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 :)
That's not what's happening at all. Remember, you're outputting HTML. In HTML, linebreaks are treated as a space.Quote:
I have \n written in the file to make a line, and it all appears as one string. How can this be fixed?
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.
link's broken lol
Okay... here's the new link :):
http://mburt.mb.funpic.org/guestbook.php