Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Windows Update issue??

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > Internet Discussion
Register FAQ Community Calendar

Editing a .txt file Online & Reading
Reply
 
Thread Tools
Old 26-03-2010, 17:06   #1
JediMaster
Inactive
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
Editing a .txt file Online & Reading

I'm looking for a simple way to have access to a .txt file online. I want to have a Text File in a folder on my FTP. Then open a HTML/PHP page & it will show me the contents of the file in ASCII format & give me the option to edit Text & Save the file (ie update the file in FTP).

Say file had Numbers, I could open a page, edit numbers & then save it.

I have a PHP script that posts from a FORM to Text File, but on page load the Form is empty (ie it does not Read the Text File).

Any free scripts that do this?
Cheers
JediMaster is offline   Reply With Quote
Advertisement
Old 26-03-2010, 20:33   #2
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Editing a .txt file Online & Reading

Gimme a min and I'll write a script for you...

---------- Post added at 19:33 ---------- Previous post was at 18:52 ----------

Here ya go.

Simple create the text file, modify the script to reflect the new filename, change the permissions so the webserver can read and write to it and you're done.

If you're not sure on the permissions thing, set it to 777 (all can read/write) - this should give the correct permissions to the file.
If you have shell access, do something like:

Code:
chown nobody:nobody textfile.txt
That should do it, if not find out which user Apache is running under by doing:

Code:
ps aux | grep httpd
OR

Code:
ps aux | grep apache
PHP Code:
<?php
// Stop the addslashes()
if (get_magic_quotes_gpc()) {
    
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list(
$key$val) = each($process)) {
        foreach (
$val as $k => $v) {
            unset(
$process[$key][$k]);
            if (
is_array($v)) {
                
$process[$key][stripslashes($k)] = $v;
                
$process[] = &$process[$key][stripslashes($k)];
            } else {
                
$process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset(
$process);
}
?>
<?php
// Edit this if you need to, change the filename to whatever you need
define ('TEXT_FILE''filename.txt');
define ('BYTES'4096); // Expected max size of the file in bytes
$message '<br />Edit the file and click Save.<br />';
?>
<html>
<head>
<title>Text Editor</title>
</head>
<body>
<?php
if ($_POST['action'] == 'save') {

    
$fileWrite fopen(TEXT_FILE"w");

    
$text $_POST['text'];
    
fwrite($fileWrite$text);
    
$message '<br />File saved, contents were: <pre>' $text '</pre><br />';
}
if (
is_resource($fileWrite)) {
    
fclose($fileWrite);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
$file 
fopen(TEXT_FILE"r");
echo 
'<textarea name="text" rows="12" cols="60">';
$contents fread($fileBYTES);
echo 
$contents;
if (
is_resource($file)) {
    
fclose($file);
}
?>
</textarea>
<br />
<input type="hidden" name="action" value="save" />
<input type="submit" value="Save" />
</form>
<?php
echo $message;
?>
</body>
</html>
Rather elegant I feel, will have to remember to keep this one for my own use.
Richard M is offline   Reply With Quote
Old 28-03-2010, 12:04   #3
JediMaster
Inactive
 
JediMaster's Avatar
 
Join Date: Jan 2004
Location: Swansea
Posts: 1,376
JediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these partsJediMaster is just so famous around these parts
Re: Editing a .txt file Online & Reading

Simply AMAZING It's PERFECT

Cheers
JediMaster is offline   Reply With Quote
Old 28-03-2010, 12:08   #4
Graham M
-
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+ Tivo V-Box VM 60MBit
Posts: 13,365
Graham M has a pair of shiny starsGraham M has a pair of shiny stars
Graham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny stars
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
Re: Editing a .txt file Online & Reading

PHP Code:
if ($_POST['action'] == 'save'
might throw an error on some servers depending on how they're configured

PHP Code:
if ((isset($_POST['action'])) && ($_POST['action'] == 'save')) 


may correct that, I haven't tested it so my syntax might be wrong, I'm a bit out of practice
Graham M is offline   Reply With Quote
Old 28-03-2010, 12:14   #5
Kymmy
Inactive
 
Join Date: Dec 2007
Posts: 18,385
Kymmy has a pair of shiny starsKymmy has a pair of shiny starsKymmy has a pair of shiny starsKymmy has a pair of shiny starsKymmy has a pair of shiny stars
Kymmy has a pair of shiny starsKymmy has a pair of shiny starsKymmy has a pair of shiny starsKymmy has a pair of shiny stars
Re: Editing a .txt file Online & Reading

There are other options on the web for example

http://phpanywhere.net/

Although designed for php files it should work with any text based file
Kymmy is offline   Reply With Quote
Old 28-03-2010, 12:22   #6
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Editing a .txt file Online & Reading

Quote:
Originally Posted by Graham M View Post
PHP Code:
if ($_POST['action'] == 'save'
might throw an error on some servers depending on how they're configured

PHP Code:
if ((isset($_POST['action'])) && ($_POST['action'] == 'save')) 


may correct that, I haven't tested it so my syntax might be wrong, I'm a bit out of practice
Aye maybe, should only throw a warning or notice though and the script would work anyway.

You're most welcome Jedi.
Richard M is offline   Reply With Quote
Old 28-03-2010, 15:32   #7
Graham M
-
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+ Tivo V-Box VM 60MBit
Posts: 13,365
Graham M has a pair of shiny starsGraham M has a pair of shiny stars
Graham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny stars
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
Re: Editing a .txt file Online & Reading

It definitely would work, I'm just being picky
Graham M is offline   Reply With Quote
Old 28-03-2010, 15:43   #8
dev
Inactive
 
Join Date: Jan 2004
Posts: 1,164
dev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond reputedev has a reputation beyond repute
Re: Editing a .txt file Online & Reading

Better to use file_get_contents() too, then you don't need to guess at the maximum size of the file.
dev is offline   Reply With Quote
Old 28-03-2010, 21:36   #9
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 46
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Editing a .txt file Online & Reading

Quote:
Originally Posted by dev View Post
Better to use file_get_contents() too, then you don't need to guess at the maximum size of the file.
Probably, I mostly look at things in C these days where everything has to be just right. :P
Richard M is offline   Reply With Quote
Old 20-04-2010, 14:04   #10
mr_bo
Inactive
 
Join Date: Nov 2005
Location: Going sideways :)
Services: V+ | o2 BB
Posts: 522
mr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful one
Re: Editing a .txt file Online & Reading

I have also used this script for a friend to update a news area written in flash to read dynamic text on her website easily.

The script is excellent and when uploaded and tested it works great, but after a short period of time the txt file address needs typing into address bar, hit f5 and then the news area updates, but updates instantly when files are uploaded.

Any ideas?
mr_bo is offline   Reply With Quote
Old 20-04-2010, 22:28   #11
Graham M
-
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+ Tivo V-Box VM 60MBit
Posts: 13,365
Graham M has a pair of shiny starsGraham M has a pair of shiny stars
Graham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny stars
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
Re: Editing a .txt file Online & Reading

It's probably the browser caching the text file, is the Flash animation using an Iframe sort of thing?
Graham M is offline   Reply With Quote
Old 20-04-2010, 23:19   #12
mr_bo
Inactive
 
Join Date: Nov 2005
Location: Going sideways :)
Services: V+ | o2 BB
Posts: 522
mr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful onemr_bo is the helpful one
Re: Editing a .txt file Online & Reading

I don't know what Iframe is, but I think you're right about caching, just what to do without having to refresh the text file.
mr_bo is offline   Reply With Quote
Old 21-04-2010, 12:55   #13
marrydavidson101
Inactive
 
Join Date: Apr 2010
Posts: 1
marrydavidson101 is an unknown quantity at this point
Re: Editing a .txt file Online & Reading

thanks for sharing this
marrydavidson101 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 21:05.


Server: osmium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum