![](/img/trans.png)
[英]php-how to move files to the folder created using userid (upload files)
[英]php-how to move files to the folder created using userid (upload files)?
需要將上傳的文件插入相應的文件夾
在這里,我根據唯一的ID創建文件夾。
我無法將文件插入文件夾。
上載文件時,文件和文件夾分別存儲。
if ($file_check_error == 0){
if(move_uploaded_file($file['tmp_name'],$upload_directory.$path)){
echo"inside 2"."<br>";
echo"Your File Successfully Uploaded";
}
$path_user = '/home/devestctrl/public_html/wp-content/plugins/est_collaboration/Files/'.$send_id;
if (!file_exists($path_user)) {
if (mkdir( $path_user,0766,false )) {
$path_move = $path_user."/".$path;
echo $path_user;
rename($path,$path_move);
echo "Success+++++++++++";
}
else{
echo $path;
echo "Failure+++++++++++";
}
}
}
$ send id是唯一的ID。
請讓我知道我哪里出錯了?
您正在弄亂您的邏輯。 首先,您移動上傳的文件
if (move_uploaded_file($file['tmp_name'], $upload_directory.$path)) {
並且僅比您嘗試創建新目錄
if (mkdir($path_user,0766,false )) {
並且僅當當前用戶從未上傳任何內容時,您才將文件重命名將其移動到其他目錄
rename($path,$path_move);
正確的邏輯:
$path = $upload_directory.DIRECTORY_SEPARATOR.$send_id
file_exists($path)
mkdir($path, 0766, false)
move_uploaded_file($file['tmp_name'], $path)
例如:
$path = $upload_directory.DIRECTORY_SEPARATOR.$send_id;
if (!file_exists($path)) {
mkdir($path, 0766, false);
}
move_uploaded_file($file['tmp_name'], $path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.