问题
i need help to solve how to create dynamically multiple folders using input type textbox
?
i can create only single dynamically subdirectory into the folder but i want to multiple subfolder when multiple input type textbox are display?
problem is that i can create only one subdirectory into the folder at time using input type textboxes
i have already create multiple textbox using javascript?
Php Code
//creating a folder
$folder = implode($_POST['folder']);
for($i=0; $i<$folder; $i++)
{
$dirPath = 'uploads/'.$folder.[$i];
$result = mkdir($dirPath);
}
Javascript
<script type="text/javascript">
var i = 0;
function changeIt(){
i++;
var table=document.getElementById("itemdetail");
var row=table.insertRow();
var cell1=row.insertCell();
cell1.innerHTML="<input type='text' name='folder[]' id=folder_"+i+"'/>";
}
</script>
Form
<form method="post" enctype="multipart/form-data">
<input type="text" name="folder[]" id="folder_0" /><br />
//dynamically creating textbox into table row
<table id="itemdetail"></table>
<input type="button" n="addnewitem" id="addnewitem"
value="Add New Question" onClick="changeIt()"/>
</form>
For Example
input type value is test1 ... uploads/subdirectory = test1
input type value is test2 ... uploads/subdirectory = test2
input type value is test3 ... uploads/subdirectory = test3
回答1:
You can try this,
if(isset($_POST)){
$folders = $_POST['folder'];
foreach($folders as $folder){
$dirPath = 'uploads/'.$folder;
$result = mkdir($dirPath);
}
}
来源:https://stackoverflow.com/questions/19822999/create-dynamically-multiple-subdirectory-into-folder-using-multiple-input-type-t