Jump to content

renaming a uploaded file


finestice

Recommended Posts

ok iv searched the forum but cant find my anwser, this is my problem:

 

iv uploaded a file and its successfully added it to /members/01/myfile.jpg

 

now further down my script i want to rename it to /members/01/$newfile.jpg

 

if tried using the the rename function but im thinking it only works when its in the temp folder on uploading the file.

iv tried for example

<? rename(/members/01/myfile.jpg,  /members/01/$newfile.jpg) ?>

I keep getting an error and 'file does not exist'

 

please any ideas will be appriecated

 

 

 

 

Link to comment
Share on other sites

well webstyles beat me to it  :P

 

1. your arguments need to be wrapped in quotes, single or double

2. if that does not work, which it should, what is the error you receive besides "file does not exist"?

3. Are you running a windows or linux server?

Link to comment
Share on other sites

ok error im getting is:

 

Warning: rename(/members/1/123abc123.jpg,/members/1/7.jpg) [function.rename]: No such file or directory in /home/stigros1/public_html/tyrehq.com/sell1.php on line 124

 

code im using is:

 

$pid = mysql_insert_id();
$newfile = $pid;
    rename('/members/'.$_SESSION[id].'/123abc123.jpg',  '/members/'.$_SESSION[id].'/'.$newfile.'.jpg');

 

any ideas iv been racking my brains out trying to figure it out

Link to comment
Share on other sites

perhaps this could be a file path issue? Let's try to debug this a little

 

$pid = mysql_insert_id();
$newfile = $pid;
        $old_file = "/members/{$_SESSION[id]}/123abc123.jpg";
        $new_file = "/members/{$_SESSION[id]}/{$newfile}.jpg";
if(is_dir($old_file)){
      $rename = rename($old_file,  $new_file);
      if(!$rename){
            print "something funky is going on";
      }
}else{
      print "$old_file is not a valid directory";
}
    

Link to comment
Share on other sites

yhh iv found the absolute path which is /home/stigros1/public_html/tyrehq.com/members/1/

 

and iv change the code to

 

$pid = mysql_insert_id();
    $newfile = $pid;
        $old_file = "/home/stigros1/public_html/tyrehq.com/members/{$_SESSION[id]}/123abc123.jpg";
        $new_file = "/home/stigros1/public_html/tyrehq.com/members/{$_SESSION[id]}/{$newfile}.jpg";
if(is_dir($old_file)){
      rename($old_file,  $new_file);
}else{
      print "$old_file is not a valid directory";
}  

 

STILL NO JOY THOU

how do i make the path http://tyrehq.com/members/1/$oldfile.jpg

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.