Advertisement
Guest User

Untitled

a guest
Nov 7th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <script type="text/javascript">
  7. var i = 0;
  8. function changeIt(){
  9. i++;
  10. var table=document.getElementById("itemdetail");
  11. var row=table.insertRow();
  12. var cell1=row.insertCell();
  13. var cell2=row.insertCell();
  14.  
  15.  
  16. cell1.innerHTML="<input type='text' name='folder[]' id=folder_"+i+"'/>";
  17. cell2.innerHTML="<input type='file' name='uploadedfile[]' id=uploadedfile_"+i+"'/>";
  18.  
  19.  
  20. }
  21. </script>
  22. <script type="text/javascript">
  23. function removeit(){
  24. var table=document.getElementById("itemdetail");
  25. var row=table.deleteRow();
  26. var cell1=row.deleteCell();
  27. var cell2=row.insertCell();
  28.  
  29.  
  30. cell1.innerHTML="<input type='text' name='folder[]' id=folder_"+i+"'/>";
  31. cell2.innerHTML="<input type='file' name='uploadedfile[]' id=uploadedfile_"+i+"'/>";
  32.  
  33.  
  34. }
  35. </script>
  36.  
  37. </head>
  38.  
  39. <body>
  40. <?php
  41. if(isset($_REQUEST['test']))
  42. {
  43.  
  44. //creating a folder
  45. $folder = $_POST['folder'];
  46. foreach( $folder as $key => $value){
  47. $dirPath = 'uploads/'.$value;
  48. $result = mkdir($dirPath);
  49. }
  50. foreach( $dirPath as $key => $newval){
  51. if ($result == '1') {
  52. //file move on
  53. $target_path = $newval;
  54. $target_path = $newval .'/' . basename( $_FILES['uploadedfile']['name']);
  55. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  56. echo "The file ". basename( $_FILES['uploadedfile']['name']).
  57. " has been uploaded";
  58. } else{
  59. echo "There was an error uploading the file, please try again!";
  60. }
  61. } else {
  62. echo $dirPath . " has NOT been created";
  63. }
  64. }
  65. }
  66. ?>
  67. <form method="post" enctype="multipart/form-data">
  68. <table>
  69. <tr>
  70. <td align="center">Upload</td>
  71. <td align="">Textbox</td>
  72. </tr>
  73. <tr>
  74. <td align="center"><input type="file" name="uploadedfile[]" id="uploadedfile_0" />
  75. </td>
  76. <td align="center"><input type="text" name="folder[]" id="folder_0" />
  77. </td>
  78. </tr>
  79.  
  80. </table>
  81. <table id="itemdetail">
  82. </table>
  83.  
  84. <input type="button" name="addnewitem" id="addnewitem" value="Add New Question" onClick="changeIt()"/>
  85. <input type="button" name="remove it" id="remove it" value="Remove Question" onClick="removeit()"/><br /><br />
  86.  
  87.  
  88. <input type="submit" name="test" value="Upload File" />
  89. </form>
  90. </body>
  91. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement