I am trying to move a file from a web interface. The move is successful but it works like copy. Instead of moving the file it copies the file in another directory leaving the original. What can I be doing wrong? Following is the sequence of code in three different files.
- filelist.php3
<head>
<title>List of Files</title>
</head>
<body>
<table border="1" cellspacing="1" cellpadding="2">
<?php
function printRow($File, $ExecutingFileLinkname, $ExecutingFile, $FilePath)
{
print "<td><a href=\"#somename\" onClick=\"window.open('$ExecutingFile?Filename=$File&Filepa
th=$FilePath', 'results', 'width=640,height=480')\">$ExecutingFileLinkname</a></td>";
}
$ExecutingFileList = array("Edit" => "webinterface.php3", "Delete" => "delete.htm", "Move" => "mo
vehtm.php3", "Copy" => "copy.htm");
$Filehandle = opendir(".");
while($File = readdir($Filehandle))
{
$FilePath = dirname($SCRIPT_FILENAME);
print "<tr>";
print "<td>$File</td>\n";
if (is_file($File))
{
for (reset($ExecutingFileList); $ExecutingFileLink = key($ExecutingFileList); next($Execu
tingFileList))
{
printRow($File, $ExecutingFileLink, $ExecutingFileList[$ExecutingFileLink], $FilePat
h);
}
}
elseif (is_dir($File))
{
for (reset($ExecutingFileList); $ExecutingFileLink = key($ExecutingFileList); next($Execu
tingFileList))
{
if ($ExecutingFileLink == "Delete" OR $ExecutingFileLink == "Move")
{
printRow($File, $ExecutingFileLink, $ExecutingFileList[$ExecutingFileLink], $Fi
lePath);
}
else
{
print "<td></td>";
}
}
}
else
{
next;
}
print "</tr>";
}
closedir($Filehandle);
?>
</table>
</body>
- movehtm.php3
<head>
<title>Copy file</title>
</head>
<body>
<p>
<?php
print "The Current directory is " . dirname(__FILE__) . "<br />\n";
print "File to be moved = $Filename<br />\n";
print "File path = $Filepath<br />\n";
?>
</p>
<hr />
<form method="post" action="move.php3">
<h2>
<b>Please enter the absolute or the relative path where the <filename> is to be moved:</b>
</h2>
<input type="text" name="Pathname" />
<?php
print "<input type=\"hidden\" name=\"Filename\" value=$Filename />";
print "<input type=\"hidden\" name=\"FilePath\" value=$Filepath />";
?>
<input type="submit" name="Move" value="Move" />
<input type="submit" name="Close" value="Close" onClick="window.close()" />
</form>
</body>
- move.php3
<?php
function Close()
{
print "<input type=\"submit\" name=\"Submit\" value=\"Close\" onClick=\"window.close()\" />";
}
define("FILEPATH", $FilePath);
$continueScript = TRUE;
if ($Move != "Move" or $Pathname == "")
{
header("Location: move.htm");
exit;
}
if ($continueScript)
{
if (!file_exists("$Filename"))
{
echo "$Filename does not exist.";
$continueScript = FALSE;
}
}
if ($continueScript)
{
if(!is_file("$Filename"))
{
echo "$Filename is not a file";
$continueScript = FALSE;
}
}
if ($continueScript)
{
if (exec("mv " . FILEPATH . "/$Filename $Pathname"))
{ echo "file moved.<br />\n"; }
else
{ echo "Move Unsuccessfull.<br />\n"; }
}
Close();
?>
Please feel free to suggest improvements in the code.
Thank You