ファイルを uploads/pension/#SOME_VARIABLE_NUMBER#/#SOME_CONSTANT_NUMBER#/ 内に移動したい
ここに私のコードがあります:
// 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);
}
ただし...「mkdir」関数でディレクトリを作成する必要がある場合、次のようになります。
mkdir() [<a href='function.mkdir'>function.mkdir</a>]: No such file or directory
わかりました、多分 mkdir は動作しませんが、名前の変更はどうですか? そこにない場合は、おそらくディレクトリが作成されます...いいえ!
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)
したがって、2 つのエラーがあります。名前の変更が機能するかどうかは確信しています。mkdir も必要ありませんが、誰が知っていますか...なぜこれらがエラーなのか、どのように修正するのか教えてもらえますか?
ありがとう!
編集: コードを変更しましたが、唯一の問題はアクセスの問題です...
rename(uploads/pension/1000_783/,uploads/pension/1001/783/) [<a href='function.rename'>function.rename</a>]: Access is denied. (code: 5)
以下は新しいコードです。基本的に、名前を3回変更します(フォルダーを移動する必要があるためですが、最後の移動が「アクセス拒否」エラーの原因です。奇妙な部分は、新しいディレクトリを削除して新しいディレクトリを作成しても、パーマを 0777 に設定してください!!!これの何が問題なのですか?
// move pension and total reward statements
// located at uploads/pension|total_rewards/%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] . "/";
$tempPensionDir1 = "uploads/pension/" . $demo_user[Users::companyID] . "/" . $demo_user[Users::companyID] . "_" . $demo_user[Users::userID] . "/";
$tempPensionDir2 = "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, 0777, true);
// move the folder
// first, move it to the pension directory
rename($oldPensionDir, $tempPensionDir1);
rename($tempPensionDir1, $tempPensionDir2);
// second, move it into the new directory
rename($tempPensionDir2, $newPensionDir);
}