Hello, so the code i have gets the files in the directory and lists them in a dropdown. what im trying to do is rename the selected dropdown file with the input of the text field. error i get is:
Warning: rename(test.php,) [function.rename]: No such file or directory in.....
For some reason its adding a comma ( , ) after the selected file from the dropdown.
I have tried a few differant ways but come up with the same problem.
Any kind of help would be appreciated.
Thank you
<form name="form" method="post">
Rename file:<input type="text" maxlength="24" style="background:#000006; color: #FF0000" value="<?php echo htmlspecialchars($text_box); ?>"
name="new_name" size="30"/>
<br /> <input type="submit" name="submit" id="submit" value="Rename" />
<?php
echo "<form>";
echo "<select name='yourfiles'>";
$dirpath = "./";
$dh = opendir($dirpath);
while (false !== ($file = readdir($dh))) {
if (!is_dir("$dirpath/$file")) {
echo "<option value='$file'>" . htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . '</option>';
}
}
closedir($dh);
echo "</select>";
echo "</form>";
$old = $_POST['yourfiles'];
$new = $_POST['$text_box'];
if($_POST['submit'])
{
if (!rename($old,$new)) {
echo "failed to rename $old...\n";
}
}
?>