Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    227
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Rename files does not work

    I have code to delete files and also option to rename it:


    PHP Code:
    $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 Code:
     <?php
    $directory 
    "uploaded_files";

    function 
    writeTable($dir) {
      echo(
    "<table border=0 align=center>\n");
      
    $files;
      
    $d opendir($dir);
      while(
    $f=readdir($d)) {
        if(
    substr($f01) == ".") 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']);

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    file permissions?

  • #3
    Regular Coder
    Join Date
    May 2006
    Posts
    227
    Thanks
    4
    Thanked 0 Times in 0 Posts
    which permission should be to rename files?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •