The message shows that you're trying to access a directory called "user_andrew" in the root of your drive (e.g. "C:\user_andrew\"). Is that correct?
No, user_andrew is located inside my webroot. I know this is a bad practice, but I just wanted to know whether it will work first.
user_andrew is the $_SESSION['folder']
echo"<input type=hidden name=filename value='";
$filename;
echo "'>
</form>";
I used the code above because I manage to get a working solution. However, this working solution produced a new window which is not as I wanted it to do. I wanted it to be in one window.
This is the working solution.
index.php
if ($handle = opendir('.\\'.$folder.'\cfile\\'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != ".." && $file != ".")
{
echo "<a href=scriptedit.php?path=.&filename=$file>$file</a><br />";
}
}
closedir($handle);
}
scriptedit.php
<?php
$path=$_REQUEST['path'];
$filename=$_REQUEST['filename'];
?>
<html>
<head>
<title>Script example</title>
<script language="Javascript" type="text/javascript" src="../edit_area/edit_area_full.js"></script>
<script language="Javascript" type="text/javascript">
// initialisation
editAreaLoader.init({
id: "content" // id of the textarea to transform
,start_highlight: true // if start with highlight
,allow_resize: "both"
,allow_toggle: true
,word_wrap: true
,language: "en"
,syntax: "c"
,toolbar: " save, |, search, go_to_line, |, undo, redo,"
,save_callback: "my_save"
});
// callback functions
function my_save(id, content){
form1.content1.value=content;
document.forms["form1"].submit();
}
</script>
</head>
<body>
<textarea name=content id=content style="height: 700px; width: 780px;"><?php
$script="edit";
if($filename!="scriptinclude.php"){
include "scriptinclude.php";
}
else{ echo "Scriptinclude may not be edited";}
?>
</textarea>
<form name=form1 method=post action=scriptupdate.php>
<table>
<tr><td><textarea name=content1 id=content1 style="height: 0px; width: 0px;">
</textarea></td></tr>
</table>
<input type=hidden name=path value='<?php echo $path;?>'>
<input type=hidden name=filename value='<?php echo $filename;?>'>
</form>
</body>
</html>
scriptinclude.php
<?php
session_start();
if($script=="edit")
{
//$lines = file("../$path/upload/$filename");
//$lines = file("$path/upload/$filename");
$lines = file($path."/".$_SESSION['folder']."/cfile/".$filename);
foreach($lines as $line)
{
echo str_replace("</textarea>","<textarea>",$line);
}
}
else
{
$content= stripslashes(str_replace("<textarea>","</textarea>",$_REQUEST['content1']));
}
?>
scriptupdate.php
<?php
session_start();
//chdir($_REQUEST['path']."/upload");
chdir($_REQUEST['path']."/".$_SESSION['folder']."/cfile");
$fp = fopen($_REQUEST['filename'], 'w');
include "scriptinclude.php";
fwrite($fp, $content);
fclose($fp);
//include 'vars.php';
header('Location: ../index.php');
?>
All of these script works from the functionality works as I wanted. It is just it is not in the same page. It open a new window.
where do you ever define the variables $script, $path, and $filename ?
Sorry, I am new to PHP. I though that
include "scriptinclude.php";
is just a link so that you don't have to write the code all over again. As I study authentication for the mysql database. Usually the mysql_connect..... always using include.
So, as all of them are linking to index.php. I don't have to define it again. May I know how to define it in the script include?
$filename does exist, it must have an empty/NULL value.
Yes, I notice it from the watch variable. That it didn't receive any value.
I believe it come from this part
$path=$_REQUEST['path'];
$filename=$_REQUEST['filename'];
how can I obtain it the value for $filename?