Ok, so I debated putting this in the VIP only section because I only want intelligent responses and this is part of a bigger project I'm working on so I didn't want to release too much of the source yet but, fuck it.
So, here's my problem. I can't figure out how to open the contents of a file in a textarea and then edit the file. Don' t really have a specific question to be honest. I've been working on this for days with literally zero results. At this point I'm running out of ideas and I need a fresh pair of eyes. So friends, take a look and tell me if you see the probably glaring error in my code:
These are the file functions
function view_files($dir)
{?>
<table>
<tr>
<form method='POST' action='?act=file&dir=<?php echo base64_encode($dir);?>'>
<td><input type='text' name='dir' size='50' value='<?php echo $dir; ?>'>
<input type='submit' value='Go'></form></td
</tr>
<table border='1'><tr>
<td width='175'><b>Name</b></td>
<td><b>Size</b></td>
<td><b>Permissions</b></td>
<td><b>Edit</b></td>
<td><b>Delete</b></td>
<td><b>Chmod</b></td>
</tr>
<?php
if($handle = opendir($dir))
{
while(($file = readdir($handle)) !== false)
{
if($file != '.' && $file != '..')
{?>
<table><td>
<?php echo $file; ?>
<td width='165'><a href='?act=edit&file=<?php echo base64_encode($file);?>'><b id='me'><u>Edit</u></b></a></td>
<td width='225'><a href='?act=del'><b id='me'><u>Delete</u></b></a></td>
<td width='190'><a href='?act=chmod'><b id='me'><u>Chmod</u></b></a></td>
</td></table>
<?php
}
}
}
}
function edit_files($file)
{
if(isset($_POST['f']) && isset($_POST['d']))
{
$handle = fopen($_POST['f'], 'w');
if(!$handle)
{
echo 'Failed to open selected file.';
}
else
{?>
<form method='POST' action='?act=edit&file=<?php echo base64_encode($file);?>'><textarea rows='17' cols='70' name='d'><?php
$data = htmlspecialchars(file_get_contents($_GET['edit']));
echo $data;
fwrite($handle, $_POST['d']);
}
if(file_exists($file))
{
$handle = fopen($file, 'r');
$contents = fread($handle, filesize($file));
echo htmlspecialchars($contents);
}?>
</textarea><input type='submit' value='Save Changes' /></form><?php
}
}
Here's where it starts:
<?php
if(isset($action) && !empty($action))
{
if($action == 'file')
{?>
<table border='1'><th><b><a id='info' href='?act=file'>[ File Management ]</a></b></th></table><?php
view_files($dir);
}
elseif($action == 'edit')
{?>
<table border='1'><th><b>[ Edit Files ]</b></th></table><?php
edit_files($file);
}
By the way $action == $_GET['act'] just so you know. I think that is all the relevant code. What basically happens is when I click on the edit button in my script, it only posts the [ Edit Files ] table header and that's it. So.. Idk I've been working on this for days with no results.