1

我需要帮助来解决这个问题文件没有被上传到动态创建的文件夹/子文件夹中!

创建一个动态subfolder使用input type text,当我上传文件移动到uploads folders但未移动到subfolder哪个是创建使用input type text?

但动态创建功能工作正常,还向我显示在文本框中输入到上传文件夹的文件夹

这是我的代码

//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";
 }
}
4

2 回答 2

1

尝试这个,

代替

 $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";
}
于 2013-11-06T16:52:38.887 回答
0

$results 在哪里定义?你在这里使用它:

$target_path = 'uploads/'.$results;

为什么?

此外, $result 是 mkdir() 的真或假返回,因此您也不能使用它。

于 2013-11-06T16:49:04.303 回答