Jump to content

Getting the contents of a file.


DJTim666

Recommended Posts

Is it possible to get the contents of a file; display the contents in a textbox; and edit the contents of that file. Then click a button and change the contents to the new updated file.

 

The reason I want to know this is because I have programmers on my site and I don't want them to have access to the FTP or cPanel. They will jus enter the name of the file, click submit, be able to edt and replace that file. All without FTP or cPanel :).

 

I hope this is possible.

 

--

DJ

Link to comment
Share on other sites

I came up with this script based on the links you provided. I'm sure it is a security nightmare waiting to happen, but it shows that this can be done easily (since I still consider myself a php noob).

 

<html>
<head>
<style type="text/css">
#editbox { width:500px; height:200px; }
</style>
</head>
<body>
<?php
if ($_GET['editbox'] != ""){
$filename = 'fread_text.txt';
$somecontent = $_GET['editbox'];
if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'w')) {
         echo "Cannot open file ($filename)";
         exit;
    }
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
    echo "Success, wrote ($somecontent) to file ($filename)";
    fclose($handle);
} else {
    echo "The file $filename is not writable";
}
}else{
$filename = "fread_text.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
echo "<form action='fread.php' method='get'>
		<input type='text' name='editbox' id='editbox' value='$contents'></input>
		<input type='submit' value='Submit' />
	  </form>";
fclose($handle);
}
?>
</body>
</html>

 

My fread_text.txt file just had some numbers in it like "293842938" to start with.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.