Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); // This line is added in order use sessions
- // The variables that are passed from the signin.php page
- $username = $_POST['email'];
- $password = $_POST['pwd'];
- // variables required in order to access the database
- $servername = "localhost";
- $usrName = "root";
- $passW= "root";
- $dbname = "reg";
- // create connection
- $conn = new mysqli($servername, $usrName, $passW, $dbname);
- if ( $conn->connect_error ){
- die("Connection unsuccessful: " . $conn->connect_error);
- }
- $sql = "SELECT password, fname FROM personalData WHERE email = '" . $username . "'";
- $result = $conn->query($sql);
- if ( $result->num_rows > 0 )
- {
- //echo "there are some values in the table <br>";
- // This while loop would work only once (because there will only be one row with the same email
- while ( $row = $result->fetch_assoc() )
- {
- $fn = $row["fname"];
- $realPass = $row["password"]; // this line will store the correct password (based on the username)
- //echo "The first name is: " . $fn . "<br>";
- }
- // If the user input password is equal to the real password in the database, the user is greeted!
- // Otherwise the user is notified and is asked to try the pasaword again.
- if ( $password == $realPass && $password != "" ){
- echo "Hello " . $fn . ", Welcome back! <br>";
- mkdir('usr/'.$username); // this will create a directory with the value inside $username
- // if this directory already exists, it leaves it as it is
- //include 'style.html'; // this line will include the HTML code from a file called 'style.html' into this php page
- $_SESSION['user'] = $username; // this will create a session so that we can access the username from another page
- // in the second page we write: $username = $_SESSION['user'];
- include 'style.html'; // this line will include the HTML code from a file called 'style.html' into this php page
- $dir = 'usr/'.$username.'/'; // setting the current directory
- listFolderFiles($dir);
- $_SESSION['currDir'] = $dir; // this will store the current directory
- include 'upload.html'; // this will call the upload
- include 'createDir.html'; // this will call createDir.html which contains the HTML form
- echo "<br/><a href='logout.php'>logout</a>";
- } else {
- include 'style.html';
- echo "You have entered a wrong password. Please try again by clicking <a href='signin.php'>here</a>.!";
- }
- }
- else {
- echo "The email you have entered does not exist! Please make sure that you have entered the correct email address!";
- }
- $conn->close();
- // this will display the list of files and folders in the current directory
- // Ref: http://stackoverflow.com/questions/7121479/listing-all-the-folders-subfolders-and-files-in-a-directory-using-php
- function listFolderFiles($dir){
- $ffs = scandir($dir); // scanning the current dir
- echo '<br><br>';
- echo '<table style="width:100%">';
- echo '<col width="70">';
- echo '<col width="85%">';
- echo '<col width="50">';
- echo '<col width="50">';
- echo '<tr>';
- echo ' <th></th>';
- echo ' <th>File / Folder name</th>';
- echo ' <th></th>';
- echo ' <th></th>';
- echo '</tr>';
- foreach($ffs as $ff){ // the name of the files or folders is stored as $ff in each iteration
- if($ff != '.' && $ff != '..' && $ff != '.DS_Store'){
- echo '<tr>';
- if(is_dir($dir.'/'.$ff)) // DIRECTORY SECTION
- {
- $fullDir = $dir.$ff;
- //echo '<a href="javascript: submitform('. '"'.$fullDir. '"'.')">'. $ff . '</a><br>'; // incorrect
- //echo '<a href="javascript: submitform('. "'".$fullDir. "'".')">'. $ff . '</a><br>'; // correct
- // first column is the image
- echo '<td><img src="icon_folder.png"> </td>';
- // second column is the name of file or dir
- echo '<td>'.$ff.'</td>';
- // third column is the enter button
- echo '<td>';
- echo '<form action="display.php" method="post">';
- echo '<input type="hidden" name ="folderToGo" value="'. $fullDir.'/' .'" >';
- echo '<input type = "submit" value="↵" >';
- echo '</form>';
- echo '</td>';
- // forth column is the delete button
- echo '<td>';
- echo '<form action="delete.php" method="post">';
- echo '<input type="hidden" name ="fname" value="'. $fullDir .'" >';
- echo '<input type = "submit" value="x" >';
- echo '</form>';
- echo '</td>';
- }
- else // FILE SECTION
- {
- // first column is the image
- echo '<td><img src="icon_file.png"> </td>';
- // second column is the name of file or dir
- echo '<td><a href="'.$dir.$ff.'"> '. $ff.'</a></td>';
- // third column is the enter button
- echo '<td></td>';
- // forth column is the delete button
- echo '<td>';
- echo '<form action="delete.php" method="post">';
- echo '<input type="hidden" name ="fname" value="'. $fullDir .'" >';
- echo '<input type = "submit" value="x" >';
- echo '</form>';
- echo '</td>';
- }
- echo '</tr>';
- }
- }
- echo '</table>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement