Advertisement
Delli

Untitled

Dec 19th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. session_start(); // This line is added in order use sessions
  5. // The variables that are passed from the signin.php page
  6. $username = $_POST['email'];
  7. $password = $_POST['pwd'];
  8.  
  9.  
  10. // variables required in order to access the database
  11.  
  12. $servername = "localhost";
  13. $usrName = "root";
  14. $passW= "root";
  15. $dbname = "reg";
  16.  
  17. // create connection
  18. $conn = new mysqli($servername, $usrName, $passW, $dbname);
  19.  
  20. if ( $conn->connect_error ){
  21. die("Connection unsuccessful: " . $conn->connect_error);
  22. }
  23.  
  24. $sql = "SELECT password, fname FROM personalData WHERE email = '" . $username . "'";
  25. $result = $conn->query($sql);
  26.  
  27. if ( $result->num_rows > 0 )
  28. {
  29. //echo "there are some values in the table <br>";
  30. // This while loop would work only once (because there will only be one row with the same email
  31. while ( $row = $result->fetch_assoc() )
  32. {
  33. $fn = $row["fname"];
  34. $realPass = $row["password"]; // this line will store the correct password (based on the username)
  35. //echo "The first name is: " . $fn . "<br>";
  36. }
  37.  
  38. // If the user input password is equal to the real password in the database, the user is greeted!
  39. // Otherwise the user is notified and is asked to try the pasaword again.
  40. if ( $password == $realPass && $password != "" ){
  41. echo "Hello " . $fn . ", Welcome back! <br>";
  42.  
  43. mkdir('usr/'.$username); // this will create a directory with the value inside $username
  44. // if this directory already exists, it leaves it as it is
  45. //include 'style.html'; // this line will include the HTML code from a file called 'style.html' into this php page
  46. $_SESSION['user'] = $username; // this will create a session so that we can access the username from another page
  47. // in the second page we write: $username = $_SESSION['user'];
  48.  
  49. include 'style.html'; // this line will include the HTML code from a file called 'style.html' into this php page
  50.  
  51. $dir = 'usr/'.$username.'/'; // setting the current directory
  52. listFolderFiles($dir);
  53.  
  54. $_SESSION['currDir'] = $dir; // this will store the current directory
  55.  
  56. include 'upload.html'; // this will call the upload
  57.  
  58. include 'createDir.html'; // this will call createDir.html which contains the HTML form
  59.  
  60.  
  61. echo "<br/><a href='logout.php'>logout</a>";
  62. } else {
  63. include 'style.html';
  64. echo "You have entered a wrong password. Please try again by clicking <a href='signin.php'>here</a>.!";
  65. }
  66.  
  67. }
  68. else {
  69. echo "The email you have entered does not exist! Please make sure that you have entered the correct email address!";
  70. }
  71.  
  72. $conn->close();
  73.  
  74.  
  75. // this will display the list of files and folders in the current directory
  76. // Ref: http://stackoverflow.com/questions/7121479/listing-all-the-folders-subfolders-and-files-in-a-directory-using-php
  77. function listFolderFiles($dir){
  78. $ffs = scandir($dir); // scanning the current dir
  79.  
  80. echo '<br><br>';
  81.  
  82. echo '<table style="width:100%">';
  83. echo '<col width="70">';
  84. echo '<col width="85%">';
  85. echo '<col width="50">';
  86. echo '<col width="50">';
  87. echo '<tr>';
  88. echo ' <th></th>';
  89. echo ' <th>File / Folder name</th>';
  90. echo ' <th></th>';
  91. echo ' <th></th>';
  92. echo '</tr>';
  93.  
  94. foreach($ffs as $ff){ // the name of the files or folders is stored as $ff in each iteration
  95.  
  96. if($ff != '.' && $ff != '..' && $ff != '.DS_Store'){
  97.  
  98. echo '<tr>';
  99.  
  100. if(is_dir($dir.'/'.$ff)) // DIRECTORY SECTION
  101. {
  102.  
  103. $fullDir = $dir.$ff;
  104. //echo '<a href="javascript: submitform('. '"'.$fullDir. '"'.')">'. $ff . '</a><br>'; // incorrect
  105. //echo '<a href="javascript: submitform('. "'".$fullDir. "'".')">'. $ff . '</a><br>'; // correct
  106.  
  107. // first column is the image
  108. echo '<td><img src="icon_folder.png"> </td>';
  109.  
  110. // second column is the name of file or dir
  111. echo '<td>'.$ff.'</td>';
  112.  
  113. // third column is the enter button
  114. echo '<td>';
  115. echo '<form action="display.php" method="post">';
  116. echo '<input type="hidden" name ="folderToGo" value="'. $fullDir.'/' .'" >';
  117. echo '<input type = "submit" value="&#8629;" >';
  118. echo '</form>';
  119. echo '</td>';
  120.  
  121. // forth column is the delete button
  122. echo '<td>';
  123. echo '<form action="delete.php" method="post">';
  124. echo '<input type="hidden" name ="fname" value="'. $fullDir .'" >';
  125. echo '<input type = "submit" value="x" >';
  126. echo '</form>';
  127. echo '</td>';
  128.  
  129.  
  130. }
  131. else // FILE SECTION
  132. {
  133. // first column is the image
  134. echo '<td><img src="icon_file.png"> </td>';
  135.  
  136. // second column is the name of file or dir
  137. echo '<td><a href="'.$dir.$ff.'"> '. $ff.'</a></td>';
  138.  
  139. // third column is the enter button
  140. echo '<td></td>';
  141.  
  142. // forth column is the delete button
  143. echo '<td>';
  144. echo '<form action="delete.php" method="post">';
  145. echo '<input type="hidden" name ="fname" value="'. $fullDir .'" >';
  146. echo '<input type = "submit" value="x" >';
  147. echo '</form>';
  148. echo '</td>';
  149. }
  150.  
  151. echo '</tr>';
  152.  
  153. }
  154.  
  155.  
  156. }
  157.  
  158. echo '</table>';
  159.  
  160.  
  161.  
  162. }
  163.  
  164. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement