Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <header>
- <h1>Home</h1>
- </header>
- <link rel="stylesheet" type="text/css" href="MainHomescreen.css" />
- <script src ="Scripts.js">
- </script>
- </head>
- <body>
- <?php
- session_start();
- //login cookies
- if(!isset($_COOKIE['loggedin']))
- {
- header("location:Login.php");
- }
- //gets username from login
- $username = $_SESSION['username'];
- //logout button request
- if(isset($_REQUEST['logout']))
- {
- $time = -10 + time();
- setcookie(loggedin, date("F jS - g:i a"), $time);
- header("location:Login.php");
- //ends session for security
- session_unset();
- session_destroy();
- }
- //Upload File
- if(isset($_REQUEST['submitFile']))
- {
- $target_dir = "/home/a1962403/public_html/$username/";
- $target_file = $target_dir . basename($_FILES["fileUpload"]["name"]);
- $uploadOk = 1;
- // Check if file already exists
- if (file_exists($target_file))
- {
- $error = "Sorry, file already exists.";
- $uploadOk = 0;
- }
- // Check file size
- else if ($_FILES["fileUpload"]["size"] > 500000)
- {
- $error ="Sorry, your file is too large.";
- $uploadOk = 0;
- }
- // Check if $uploadOk is set to 0 by an error
- else if ($uploadOk == 0)
- {
- $error = "Sorry, your file was not uploaded.";
- }
- // if everything is ok, try to upload file
- else
- {
- if (move_uploaded_file($_FILES["fileUpload"]["tmp_name"], $target_file))
- {
- $success = "The file ". basename( $_FILES["fileUpload"]["name"]). " has been uploaded.";
- }
- else
- {
- $error = "Sorry, there was an error uploading your file.";
- }
- }
- }
- //delete file
- if(isset($_REQUEST['deleteFile']))
- {
- //delete file
- if(isset($_POST['checkbox']))
- {
- foreach($_POST['checkbox'] as $selected)
- {
- $path = "/home/a1962403/public_html/$username/$selected";
- if(unlink($path))
- {
- $output = "$selected deleted";
- }
- else
- {
- $error = "Error deleting $selected";
- }
- }
- }
- //delete directory
- if(isset($_POST['dcheckbox']))
- {
- foreach($_POST['dcheckbox'] as $selected)
- {
- rmdir("/home/a1962403/public_html/$username/$selected");
- }
- }
- else
- {
- $error = "please select a file/directory to delete";
- }
- }
- if(isset($_REQUEST['renameFile']))
- {
- //uses checkboxes from table for files
- if(isset($_POST['checkbox']))
- {
- $checkedboxes = $_POST['checkbox'];
- $count = count($checkedboxes);
- if($count == 0)
- {
- $error = "Please select a file or directory to rename!";
- }
- if($count == 1)
- {
- foreach($_POST['checkbox'] as $selected)
- {
- //puts selected checkbox into session
- $_SESSION["selectedCB"] = $selected;
- echo "<script> renameFile(); </script>"; // then calls if($rename = $_GET['rename']) below
- }
- }
- if($count > 1)
- {
- $error = "Please only select ONE file or directory to rename at a time!";
- }
- }
- //uses checkboxes from table for directories
- if(isset($_POST['dcheckbox']))
- {
- $checkedboxes = $_POST['dcheckbox'];
- $count = count($checkedboxes);
- if($count == 0)
- {
- $error = "Please select a file or directory to rename!";
- }
- if($count == 1)
- {
- foreach($_POST['dcheckbox'] as $selected)
- {
- //puts selected checkbox into session
- $_SESSION["selectedCB"] = $selected;
- echo "<script> renameFile(); </script>"; // then calls if($rename = $_GET['rename']) below
- }
- }
- if($count > 1)
- {
- $error = "Please only select ONE file or directory to rename at a time!";
- }
- }
- }
- //finishes off changing file name!
- if(isset($_GET['rename']))
- {
- $rename = $_GET['rename'];
- $selectedCheck = $_SESSION["selectedCB"];
- //get file extension
- $fileExt = pathinfo($selectedCheck, PATHINFO_EXTENSION);
- if($rename !== "")
- {
- if($fileExt !== "")
- {
- rename("/home/a1962403/public_html/$username/$selectedCheck", "/home/a1962403/public_html/$username/$rename.$fileExt");
- }
- else if($fileExt == "")
- {
- rename("/home/a1962403/public_html/$username/$selectedCheck", "/home/a1962403/public_html/$username/$rename");
- }
- }
- if($rename == "")
- {
- $error = "Please enter a name, name cannot be empty";
- }
- }
- //download selected file(s)
- if(isset($_REQUEST['download']))
- {
- // connect and login to FTP server
- $ftp_server = "natcmt3313site.site50.net";
- $ftp_username = "a1962403";
- $ftp_userpass = "";
- $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
- $login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
- if (ftp_chdir($ftp_conn, "public_html/$username")) {
- //echo "Current directory is now: " . ftp_pwd($ftp_conn) . "\n";
- } else {
- echo "Couldn't change directory\n";
- }
- if(isset($_POST['checkbox']))
- {
- foreach($_POST['checkbox'] as $selected)
- {
- $local_file = "local.zip";
- $server_file = "$selected";
- // download server file
- if (ftp_get($ftp_conn, $local_file, $server_file, FTP_BINARY))
- {
- header("Content-type: application/local.zip");
- header("Content-length: " . filesize($local_file));
- header("Content-disposition: attachment; filename= $selected");
- echo file_get_contents($local_file);
- unlink($local_file);
- }
- else
- {
- $error = "Error downloading $server_file.";
- }
- }
- }
- else
- {
- $error = "Sorry, you can't download directories";
- }
- // close connection
- ftp_close($ftp_conn);
- }
- //Create new directory - called from Script.js
- if(isset($_GET['newName']))
- {
- $newName = $_GET['newName'];
- if($newName !== "")
- {
- //goes through files if found then breaks else continues going through
- foreach($filearray as $filename)
- {
- if($newName == $filename)
- {
- $found = true;
- break;
- }
- else if($newName != $filename)
- {
- $found = false;
- }
- }
- if($found == true)
- {
- $error = "error, directory exists already";
- }
- else //creates new directory
- {
- mkdir("/home/a1962403/public_html/$username/$newName", 0777);
- }
- }
- else if($newName == "")
- {
- $error = "Please enter a new directory name, not empty";
- }
- }
- //Share button
- if(isset($_REQUEST['share']))
- {
- if(isset($_POST['checkbox']))
- {
- $selectedArray = array();
- foreach($_POST['checkbox'] as $selected)
- {
- $selectedArray[] = $selected;
- }
- //puts selected checkbox into session
- $_SESSION["selectedShareCB"] = $selectedArray;
- echo "<script> shareSelected(); </script>";
- }
- else if(isset($_POST['dcheckbox']))
- {
- $error = "Sorry you cannot share directories";
- }
- else
- {
- $error = "Please select files to share";
- }
- }
- //file sharing with named member
- if(isset($_GET['userEmail']))
- {
- //connect to database to find email
- $mysql_host = "mysql4.000webhost.com";
- $mysql_database = "a1962403_nat";
- $mysql_user = "a1962403_nat";
- $mysql_password = "";
- $con = mysql_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database) or die ("Failed");
- $selected = mysql_select_db("a1962403_nat", $con);
- $userEmail = $_GET['userEmail'];
- $userEmail = stripslashes($userEmail);
- $query = "SELECT Username FROM Users WHERE Email = '$userEmail'";
- $result = mysql_query($query) or die(mysql_error());
- //gets related username to email
- $getRes = mysql_fetch_assoc($result);
- $userUName = $getRes['Username'];
- $rowCount = mysql_num_rows($result);
- mysql_close();
- //count cannot be > 1 as system doesn't allow when registering users
- if($rowCount == 0)
- {
- $error = "$userEmail doesn't exist! Please try again";
- }
- if($rowCount == 1)
- {
- foreach($_SESSION["selectedShareCB"] as $key => $value)
- {
- //gets source and destination
- $dir = "/home/a1962403/public_html/$userUName/SharedFiles/";
- $source = "/home/a1962403/public_html/$username/$value";
- if(file_exists($dir)) //checks for sharedfiles
- {
- $dir = "/home/a1962403/public_html/$userUName/SharedFiles/$username";
- if(file_exists($dir)) //checks for username file
- {
- //puts file name on end to copy to
- $dest = "/home/a1962403/public_html/$userUName/SharedFiles/$username/$value";
- copy($source, $dest);
- }
- else
- {
- mkdir("/home/a1962403/public_html/$userUName/SharedFiles/$username", 0777);
- $dest = "/home/a1962403/public_html/$userUName/SharedFiles/$username/$value";
- copy($source, $dest);
- }
- }
- else //if SharedFiles isn't there, creates it then sends the file
- {
- mkdir("/home/a1962403/public_html/$userUName/SharedFiles/", 0777);
- mkdir("/home/a1962403/public_html/$userUName/SharedFiles/$username", 0777);
- $dest = "/home/a1962403/public_html/$userUName/SharedFiles/$username/$value";
- copy($source, $dest);
- }
- }
- }
- }
- ?>
- <form name="mainHomescreen" action="MainHomescreen.php" method="POST">
- <nav>
- <input type="text" name="Search" value="Search" style = "color:#888;" onFocus="inputFocus(this)" onBlur="inputBlur(this)"/>
- <input type="submit" value="Logout" name="logout"/> <!-- DONE -->
- </nav>
- <sidebar>
- <input type="button" value="Create Directory" onClick="createDirectory()"/> <!--DONE-->
- <input type="submit" value="Download Selected Files/Folders" name="download"/> <!-- SMALL ISSUE -->
- <input type="button" value="Encrypt Selected" onClick="encrypt()"/><br>
- <input type="submit" value="Share Selected" name="share"/>
- <input type="button" name="upload" value="Upload File" onClick="showUpload()"/> <!-- brings up pop up--> <!-- DONE -->
- <input type="submit" value="Delete" name="deleteFile"/> <!-- DONE -->
- <input type="submit" value="Rename" name="renameFile"/><br> <!-- DONE -->
- <input type="button" value="Password Protect Folder/ File" onClick=" "/><br><br>
- </sidebar>
- <article>
- <p> <?php echo $displaypath ?> </p><br><br>
- <span class="error"><?php echo $error;?></span>
- <span class="output"><?php echo $output;?></span>
- <!-- php to create table -->
- <?php
- if(isset($_GET['directory']))
- {
- $dirName = $_GET['directory'];
- $_SESSION["dirName"] = $dirName;
- if($dirName == '.')
- {
- $currDir = $_SESSION["currDir"];
- $_SESSION["path"] = $currDir;
- }
- else //down
- {
- $currDir = $_SESSION["newDir"];
- $currPath = "$currDir/$newDir";
- $_SESSION["path"] = "$currPath";
- }
- }
- else
- {
- $_SESSION["path"] = getcwd();
- $dirName = $username;
- }
- $path = $_SESSION["path"];
- $displaypath = $path;
- //open file names
- $dir = opendir("$path/$dirName/");
- //fill array with directory and file names
- $filearray = array();
- $directory = opendir("$path/$dirName");
- while (($file = readdir($directory)) !== false)
- {
- $filearray[] = $file;
- }
- echo '<table cellpadding="10" cellspacing="0" style="width:100%">';
- echo '
- <tr>
- <th> </th>
- <th> </th>
- <th>File</th>
- <th>Date</th>
- <th>Size</th>
- </tr>
- ';
- //List files in directory
- while (($file = readdir($dir)) !== false)
- {
- if($file !== '..')
- {
- if($dirName == $username)
- {
- if($file !== '.')
- {
- $size = filesize("$path/$dirName/$file");
- if($size == '4096')
- {
- echo '<tr class="bottomline" id="$rownumber">';
- echo "<td><input type='checkbox' name='dcheckbox[]' value='". $file . "' </td>";
- echo "<td><img src='/home/a1962403/public_html/images/Document.png'></td>";
- echo "<td><a href='MainHomescreen.php?directory=$file'>$file</a></td>";
- echo "<td></td>";
- echo "<td></td>";
- echo '</tr>';
- }
- else
- {
- //gets the file date, string needed decoding otherwise throws error.
- $date = @filemtime($file);
- $date = date("F d Y H:i:s.", filemtime(utf8_decode("$path/$dirName/$file")));
- //<!--prints a table row-->
- echo '<tr class="bottomline">';
- echo "<td><input type='checkbox' name='checkbox[]' value='". $file . "' </td>";
- echo "<td><img src='/home/a1962403/public_html/images/file.png'></td>";
- echo "<td>$file</td>";
- echo "<td>$date</td>";
- echo "<td>$size bytes</td>";
- echo '</tr>';
- }
- }
- }
- else //dir not username therefore need ..
- {
- $size = filesize("$path/$dirName/$file");
- if($size == '4096')
- {
- echo '<tr class="bottomline" id="$rownumber">';
- echo "<td><input type='checkbox' name='dcheckbox[]' value='". $file . "' </td>";
- echo "<td><img src='/home/a1962403/public_html/images/Document.png'></td>";
- echo "<td><a href='MainHomescreen.php?directory=$file'>$file</a></td>";
- echo "<td></td>";
- echo "<td></td>";
- echo '</tr>';
- }
- else
- {
- //gets the file date, string needed decoding otherwise throws error.
- $date = @filemtime($file);
- $date = date("F d Y H:i:s.", filemtime(utf8_decode("$path/$dirName/$file")));
- //<!--prints a table row-->
- echo '<tr class="bottomline">';
- echo "<td><input type='checkbox' name='checkbox[]' value='". $file . "' </td>";
- echo "<td><img src='/home/a1962403/public_html/images/file.png'></td>";
- echo "<td>$file</td>";
- echo "<td>$date</td>";
- echo "<td>$size bytes</td>";
- } echo '</tr>';
- }
- }
- }
- echo '</table>';
- $newDir = "$path/$dirName";
- $_SESSION["newDir"] = $newDir;
- $currDir = $path;
- $_SESSION["currDir"] = $currDir;
- closedir($dir);
- ?>
- <p> description here when you hover over something maybe with buttons too? </p>
- </article>
- </form>
- <!-- upload a file -->
- <div id="fileUpload">
- <div id="uploadPopup">
- <form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="uploadForm" method="post" name="uploadForm" enctype="multipart/form-data">
- <img id="close" src="/home/a1962403/public_html/images/Exit.png" onclick="hideUpload()">
- Select file to upload: <input name="fileUpload" type="file" /><br />
- <input type="submit" value="Upload File" name="submitFile"/>
- </form>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement