Advertisement
Anna_Kurmanova

file upload 2 pages of mess

Jun 9th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. Main page.
  2. <?php
  3. mb_internal_encoding('utf-8');
  4. define('TITLE','File upload');
  5. ?>
  6.  
  7. <!DOCTYPE html>
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  11. <style>
  12.  
  13.  
  14. #add {
  15. height:50px;
  16. width:250px;
  17. float:right;
  18.  
  19. }
  20. form {
  21. width:500px;
  22.  
  23. }
  24.  
  25. </style>
  26.  
  27. <title><?php echo TITLE; ?></title>
  28. </head>
  29.  
  30. <body>
  31. <?php
  32. //file upload on main page
  33.  
  34.  
  35. if (isset($_POST['name'])) {
  36. move_uploaded_file($_FILES['file']['tmp_name'],'add_article_form.php' . $_POST['name'] . '.txt');
  37. echo 'file uploaded: ' . $_POST['name'] . '.txt';
  38.  
  39.  
  40. }
  41. echo '<br>' ;
  42. echo '<br>' ;
  43.  
  44. ?>
  45.  
  46. <form action = "add_article_form.php" method = "POST">
  47.  
  48. <input id = "add" type = "submit" value="Upload">
  49.  
  50. </form>
  51.  
  52.  
  53.  
  54. <h2>Files</h2>
  55.  
  56. <?php
  57. //display file name
  58.  
  59. $resource = opendir('../uploads/');
  60.  
  61. while(($entry = readdir($resource))!== FALSE)
  62. {
  63. if($entry != '.' && $entry != '..'){
  64. echo "<a href = \"#\">$entry</a>" . '<br>';
  65.  
  66. } else {
  67. "<a href = \"#\">$entry</a>" . '<br>';
  68.  
  69. }
  70. }
  71.  
  72. echo '<br>';
  73. ?>
  74. </body>
  75. </html>
  76.  
  77. PAGE #2///////////////////////////////////////////////////////////////////////////////////////////////
  78. <?php
  79. mb_internal_encoding('utf-8');
  80. define('TITLE','Добавить статью');
  81. ?>
  82.  
  83. <!DOCTYPE html>
  84. <html>
  85. <head>
  86.  
  87. <style>
  88. #add
  89. {
  90. height:50px;
  91. width:250px;
  92. }
  93. </style>
  94.  
  95. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  96.  
  97. <title><?php echo TITLE; ?></title>
  98.  
  99. </head>
  100.  
  101. <body>
  102.  
  103. <!--The upload form, second page -->
  104.  
  105. <form action = "../uploads/" method="POST" enctype="multipart/form-data" >
  106. Название статьи: <br>
  107. <input type = "text" name = "name" value = "text"><br><br>
  108. Файл:<br>
  109. <input type = "file" name="file"><br><br>
  110. <input id = "add" type = "submit" value="add"><br><br>
  111.  
  112. </form>
  113.  
  114. <p><a href = "index.php">Back</a></p>
  115.  
  116.  
  117. </body>
  118. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement