我需要帮助来解决这个问题文件没有被上传到动态创建的文件夹/子文件夹中!
创建一个动态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";
}
}