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
https://forums.phpfreaks.com/topic/71473-getting-the-contents-of-a-file/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.