文件未上传到动态创建的文件夹/子文件夹中 [英] Files not being uploaded in dynamically created folders/subfolders

查看:112
本文介绍了文件未上传到动态创建的文件夹/子文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来解决此问题,文件无法上传到动态创建的文件夹/子文件夹中!

i need help to solve this problem Files not being uploaded in dynamically created folders/subfolders!

使用input type text动态创建subfolder,并且当我将文件上传到uploads folders而不是使用input type text?

creating a dynamically subfolder using input type text and when i uploaded file moved to uploads folders but not moved to subfolder which is create using input type text?

但动态创建功能可以正常工作,并且还可以向我显示在文本框中键入到上载文件夹中的文件夹

but dynamically creating function working fine and also showing me folder which is typed in the textbox into the upload folder

此处是我的代码

//creating dynamically subfolders 
$folder = $_POST['folder'];
foreach( $folder as $key => $value){
$dirPath = 'uploads/'.$value;
$result = mkdir($dirPath);
}

if ($result == '1') {

//file move on function
$target_path = 'uploads/'.$results;
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
" has been uploaded";

} else{
echo "There was an error uploading the file, please try again!";
}
} else {
echo $dirPath . " has NOT been created";
}
}

<form method="post" enctype="multipart/form-data">
<input name="uploadedfile" type="file" /><br />
<input type="text"  id="folder" name="folder"><br />
<input type="submit" name="test" value="Upload File" />
</form>

我的脚本已经解决,我的问题已解决

//creating a folder 
$folder = $_POST['folder'];
$dirPath = 'uploads/'.$folder;
$result = mkdir($dirPath);

if ($result == '1') {

//file move on        
$target_path = $dirPath .'/' . basename( $_FILES['uploadedfile']['name']); 

  if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
     echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
" has been uploaded";

  } else{
     echo "There was an error uploading the file, please try again!";
  }

 } else {
   echo $dirPath . " has NOT been created";
 }
}

推荐答案

尝试一下,

替换

 $target_path = 'uploads/'.$results; 

进入

$target_path = $dirPath.'/';

否则,

$target_path = $dirPath .'/'. basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}

这篇关于文件未上传到动态创建的文件夹/子文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆