View Full Version : Editing files online
theabyss
05-04-2003, 01:43 AM
I'm wondering if I can have a text box on a webpage open a file on my server. I've seen this on Tripod before. An advanced editor or some sort. I'll of course have it in a password protected directory. Is this possible with PHP?
mouse
05-04-2003, 02:23 AM
Yeah, with varying complexity. Using the fopen (http://php.net/fopen), fread (http://php.net/fread) and fclose (http://php.net/fclose) functions.
theabyss
05-05-2003, 01:08 AM
Whoa! I don't think I can understand that :o I tried searching the internet, but I couldn't find anything that made sense. Is there a way where I can type a filename in an input area and press submit and the source will load in a textarea? Then, I can edit it and press submit and it will be saved? That would be cool.
Thanks!
[added:]
It doesn't have to be PHP. If it can be done with JavaScript, that'll be OK.
BroChris
05-06-2003, 03:40 PM
http://www.hotscripts.com/Detailed/17622.html
Above is a link to php script which allows for web editing of your files. Since I don't know php very well, it was perfect for me. However, in order for it to work, you need to chmod your files to 646, which makes the file writable by others (making the site less secure).
theabyss
05-07-2003, 02:54 AM
I'm having trouble right now. It shows the login screen, but it keeps loading the login screen when I enter my username and password. My cookies are enabled, so that's not the problem. Not sure what it is. I'll try figuring it out some more after I post this message.
ConfusedOfLife
05-07-2003, 09:43 PM
Well, let's see if I'm right!
Instead of using an input box, I think a select box (combo box) is more appropriate. So, at first you read all the files in your directory and make your select box. When one of the items is chosen inside the select box, so, you submit the form and get the file name back, you open it by fopen and put its contents inside of a textbox and also make a hidden input to hold the name of the file. If the submit button is pressed, then you get your textarea back and you update the file name that is held in that hidden input value( You do it with fputs).
How's that?!
theabyss
05-08-2003, 01:11 AM
Hey. I couldn't get that to work since I never dealed with forms. I found the following code at: http://www.free2code.net/tutorials/programming/php/4/file2.php
<?php
$filename = 'WEB_ADDRESS';
$fp = fopen($filename, "a+");
$string = "\nline5";
$write = fputs($fp, $string);
fclose($fp);
?>
I found that this works, but how can edit what's added to the file??? How can I change the string variable online? I'll also need to change the filename being edited. I wouldn't know how to create a form that lets me type the filename and string variables in, so could somebody show me how I'd do that? Thanks.
This is starting to make sense :)
ConfusedOfLife
05-09-2003, 12:41 AM
You know my friend, I can give ya the whole program, but you know something? Do you really enjoy it? You can write this program very easily if you read about file handling and forms, that make a big and significant part of PHP. So, if you don't wana learn it yourself, you should always copy and paste others codes. Just my 2 cents
theabyss
05-09-2003, 12:49 AM
The site link I have above has the best explained code. PHP.net didn't have anything that significant at all. They didn't explain it too much. I just need a site that explains how to put a form and PHP together to create some kind of file editing service. That would be a great site. If you don't have a site that I can go to, then can you write one for me? Thanks! :thumbsup:
ConfusedOfLife
05-09-2003, 01:59 PM
Haha! Ok, I see what I can do, but I'm awfully busy these days, I really can't promise when it's gonna be ready. You said about a site to tell you what to do, I think it's not a bad idea if you grab a book and start to learn these parts on your own. php.net is just a big reference, it comes handy if you know what you're looking for!
theabyss
05-09-2003, 08:33 PM
OK. I'll keep searching for sites online, and occasionally visit php.net for info. I'll probably figure this out by the time you get the program done. My first post here is when I started to research on PHP so I'm all new to this stuff. It doesn't seem that hard, but it's a little frustrating at first. Thanks for your help! :)
theabyss
05-11-2003, 03:14 AM
Sweet! I've found a very good one but something doesn't make sense.
<?
...
...
error_reporting(0);
$self = "http://";
$self .= $HTTP_HOST;
$self .= $PHP_SELF;
global $activity;
global $fileselector;
...
...
?>
Does anybody know what's going on here? I think I'm supposed to get rid of two of the self variables and leaving one, but not sure what to do.
I've attached the zip file so you can see the file.
ConfusedOfLife
05-11-2003, 06:11 AM
Hi man, how's it going?!
Well, finally I made a kind of dummy script, it's not that beautiful, but it even works! Run the index.php file and see what you get.
Hope you like it!
theabyss
05-11-2003, 05:15 PM
Thanks so much! This helps me a lot. When I'm at school I can make web entries now because I have a weblog on my own server. I just tested it by adding an exclamation point in one of my pages. Works great! I have the program in a password protected directory.
Thanks a lot for your help :thumbsup: :cool:
theabyss
05-11-2003, 07:54 PM
Hey. Thanks again. I just customized everything to make it more efficient. Instead of one Edit button on the bottom, I put it one of the table cells in the file list. That way I don't have to scroll down. I also removed the size and Last modified things, because i really don't need those.
Also, I noticed the $HTTP variables. That's what I needed to make it work the first time. I made the text box used to edit the files bigger.
I've attached the file so you can see the changes I made. Have a nice day! :cool:
<edit>
Reattached extremely modified version of this script.
</edit>
ConfusedOfLife
05-11-2003, 11:28 PM
Hi
I'm glad that you liked it, but I don't think that you should put all those Edit buttons in there! If you wana keep your button always present in the page, it's better that you put it in another frame or just JS to fix the button in your page. Making the text area bigger was fine, it's really needed.
Have fun,
bijan
theabyss
05-12-2003, 01:37 AM
Javascript is another thing I don't know anything about :o I learned a little bit about tables, but then I learned that tables were bad. So, I stuck with divs and spans. But, now I'm only dealing with stylized P elements. That way the page is in paragraph form.
It was the easiest way to put edit buttons on each row that I could think of :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.