Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-03-2006, 04:43 PM   PM User | #1
toplisek
Regular Coder

 
Join Date: May 2006
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
toplisek has a little shameless behaviour in the past
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']);
toplisek is offline   Reply With Quote
Old 05-03-2006, 04:57 PM   PM User | #2
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
file permissions?
GJay is offline   Reply With Quote
Old 05-03-2006, 04:58 PM   PM User | #3
toplisek
Regular Coder

 
Join Date: May 2006
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
toplisek has a little shameless behaviour in the past
which permission should be to rename files?
toplisek is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:31 AM.


Advertisement
Log in to turn off these ads.