EvilZone
Programming and Scripting => Web Oriented Coding => : lucid May 10, 2013, 10:14:56 PM
-
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.
-
Hit me up on Skype and I'll give you access to http://moijo.org a project I haven't worked on for some month but I think you will get answers regarding file edit in php/js from its alpha.
too drunk to paste code here but skype you know ^_^
-
Why is it that by default it only shows the text input bar with the directory, and the table header that says File, Size, Permissions, etc? Here's what my view files function looks like now:
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 getcwd(); ?>'>
<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 != '..')
{
$path_and_file = $dir .'/'. $file;
$encoded_path_and_file = base64_encode($path_and_file);
?>
<tr>
<td><?php echo $file; ?></td>
<td><?php echo filesize($path_and_file);?></td>
<td>perms</td>
<td width='165'><a href='?act=edit&file=<?php echo $encoded_path_and_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>
</tr
<?php
}
}
}
}
It's only slightly different from yours. What I want it to do is display all files in the current directory and the edit, delete and chmod buttons by default, without having to click on the Go button next to the input box. That's how it used to work and even if I switch back to the exact same function that I had before it still only shows the input box with the current working directory..