PHP: How do I rename a directory where the parent directory is variable?

Posted by gsquare567 on Stack Overflow See other posts from Stack Overflow or by gsquare567
Published on 2010-06-01T15:56:16Z Indexed on 2010/06/01 16:03 UTC
Read the original article Hit count: 221

Filed under:
|

i would like to move the files inside uploads/pension/#SOME_VARIABLE_NUMBER#/#SOME_CONSTANT_NUMBER#/

here is my code:

// move pension statements
// located at uploads/pension/%COMPANY_ID%/%USER_ID%/%HASH%
// so just move the %USER_ID% folder to the new company
$oldPensionDir = "uploads/pension/" . $demo_user[Users::companyID]  . "/" . $demo_user[Users::userID] . "/";
$newPensionDir = "uploads/pension/" . $newCompanyID      . "/" . $demo_user[Users::userID] . "/";
// see if the user had any files, and if so, move them
if(file_exists($oldPensionDir)) {
 // if it doesnt exist, make it
 if(!file_exists($newPensionDir))
  mkdir($newPensionDir);
 // move the folder
 rename($oldPensionDir, $newPensionDir);
}

however... when i need to make the directory with the "mkdir" function, i get:

mkdir() [<a href='function.mkdir'>function.mkdir</a>]: No such file or directory

ok, maybe the mkdir won't work, but what about the rename? perhaps that will make the directory if it's not there... nope!

rename(uploads/pension/1001/783/,uploads/pension/1000/783/) [<a href='function.rename'>function.rename</a>]: The system cannot find the path specified. (code: 3)

so, there are two errors. i'm pretty sure if the renaming works, i won't even need the mkdir, but who knows... can anyone tell me why these are errors and how to fix them?

thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about file-rename