...

View Full Version : Rename files does not work



toplisek
05-03-2006, 05:43 PM
I have code to delete files and also option to rename it:




$fn = $directory . "/" . $_POST['filename'];


if($_POST['delete']) unlink($fn);
else if($_POST['newname']) rename($fn, $directory . "/" . $_POST['newname']);


Do you know why it does not work code?

all code is the following:


<?php
$directory = "uploaded_files";

function writeTable($dir) {
echo("<table border=0 align=center>\n");
$files;
$d = opendir($dir);
while($f=readdir($d)) {
if(substr($f, 0, 1) == ".") continue;
echo(
"\t<tr class=manageimg>\n" .
"\t\t<td>" . '<img src="' . "$dir/$f" . '"></td>' . "\n" .
"\t\t<td width=50></td>\n" .
"\t\t<td>\n" .
"\t\t\t<form action=\"$PHP_SELF\" method=\"post\">\n" .
"\t\t\t\t" .'File name:'.$f.'<br><br>' . "\n\n" .
"\t\t\t\t" . 'Name:<input type="text" name="newname"><br><br>' . "\n\n" .
"\t\t\t\t" . 'Caption:<input type="text" name="caption"><br>' . "\n" .
"\t\t\t\t" . '<input type="checkbox" name="delete">Remove this image<br><br>' . "\n" .
"\t\t\t\t" . '<input type="hidden" name="filename" value="' . $f . '">' . "\n" .
"\t\t\t\t" . '<input type="submit" value="Save"><br><br><br>' . "\n" .
"\t\t\t</form>" .
"\t\t</td>\n" .
"\t</tr>\n"
);
}

closedir($d);
echo("</table>\n");
return "";

}

if(!isset($_POST['filename'])) die(writeTable("uploaded_files"));
else if(!file_exists("$directory/" . $_POST['filename']) || strpos($_POST['filename'], "./") != -1) die();

$fn = $directory . "/" . $_POST['filename'];

if($_POST['delete']) unlink($fn);
else if($_POST['newname']) rename($fn, $directory . "/" . $_POST['newname']);

GJay
05-03-2006, 05:57 PM
file permissions?

toplisek
05-03-2006, 05:58 PM
which permission should be to rename files?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum