Archivatory Update #003 | Delete your data, your account, and upload a profile photo!
utopian-io·@jrswab·
0.000 HBDArchivatory Update #003 | Delete your data, your account, and upload a profile photo!
 #### Repository https://github.com/jrswab/archivatory ### New Features #### What feature(s) did you add? - User Settings Page. - Photo upload for coming profile pages. - Account Deletion (removes user account and all data). - Display file size in MB instead of bytes. - Ability for users to delete their content from the server. #### How did you implement it/them? ##### User Settings Page. ###### Profile Image Display: ``` <?php $timeIs = time(); // set time // forces photo reload to let user know the upload succeeded. $proPho = shell_exec('ls uploads/profiles | grep ' .htmlspecialchars($_SESSION['username'])); // if no photo is found for the user, use current archivatory logo if (!$proPho) { echo '<img src="img/archieTheArchivonaut.png" class="rounded img-fluid" style="max-height:250px;"/>'; } else { echo '<img src="uploads/profiles/'.$proPho.'?='.$timeIs.'" class="rounded img-fluid" style="max-height:250px;"/>'; } ?> ``` ###### Profile Image Upload Form: ``` // Upload user profile photo with execs/proPhoUp.php to uploads/profiles/ <div id="uploadPro" class="d-inline-flex flex-column justify-content-center"> <h5>Upload Profile Image:</h5> <p>Max allowed file size is 2MB</p> <form id="profilePhoto" class="form-group" enctype="multipart/form-data" action="execs/proPhoUp.php" method="POST"> <input class="form-input" type="file" name="file" /> <br /><br /> <button id="proPhoClick" onclick="pgShow()" class="btn btn-success" name="submit" type="submit">Upload Photo</button> <br /><br /> // Hide progress bar until button is pressed <div id="bar" style="display:none;"> <div class="progress"> <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div> </div> <br> </div> </form> </div> ``` ###### Account Deletion Form: ``` // Send account deletion data to execs/delUser.php script via POST <form id="delForm" class="d-flex flex-wrap justify-content-center" action="execs/delUser.php" method="POST"> <p style="font-size:1em; text-align:center;"> You are about to delete your account.<br /> <strong>This process is permanent!</strong><br /> Click here only if you understand and would like to continue. </p> <input name="user" type="text" style="display:none" value="<?php echo htmlspecialchars($_SESSION['username']); ?>"> </input> <button type="submit" name="delAccount" class="btn btn-danger btn-lg"> Yes, delete my account. </button> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </form> ``` ###### Settings Page Javascript: ``` <script> // account deletion popup function pop(){ document.getElementById("delButton").style = "display: none"; document.getElementById("delAlert").style = "display: block"; } // show progress bar on photo upload function pgShow() { var bar = document.getElementById("bar"); bar.style.display = "block"; } </script> ``` [Full source code found for settings.php at Github](https://github.com/jrswab/archivatory/blob/master/settings.php) ##### Photo upload for coming profile pages: ``` <?php include '../config/topMem.php'; if (isset($_POST['submit'])) { $file = $_FILES['file']; // define file $fileName = $_FILES['file']['name']; // grab the file name $fileTmpName = $_FILES['file']['tmp_name']; // define file temp name $fileSize = $_FILES['file']['size']; // grab the file size $fileError = $_FILES['file']['error']; // define error code $fileType = $_FILES['file']['type']; // grab the file type // separate the file extension from the file name $fileExt = explode('.', $fileName); // convert the extension to lower case $fileActualExt = strtolower(end($fileExt)); // allowed file extensions $allowed = array('jpg', 'jpeg', 'png'); // check if file extension is allowed first if (in_array($fileActualExt, $allowed)) { if ($fileError === 0) { // check for no error codes if ($fileSize < 2202010) { // make sure file size is less than 2MB // give the upload a unique name echo $_SESSION['username']; $fileNameNew = $_SESSION['username'].".".$fileActualExt; // define file upload end location $fileDestination = '../uploads/profiles/'.$fileNameNew; // move the file move_uploaded_file($fileTmpName, $fileDestination); // return user to settings.php header('Location: ../settings.php'); } else { echo "Your file is too big. For best results please keep your file under 250MB."; } } else { echo "There was an error during uploading. Please try again."; } } else { echo "Sorry, the ".$fileActualExt." file type is not supported."; } } include '../config/bottom.html'; ``` [Full source code found for execs/proPhoUp.php at Github](https://github.com/jrswab/archivatory/blob/master/execs/proPhoUp.php) ##### Account Deletion (removes user account and all data). ``` <?php include '../config/topMem.php'; require '../config/config.php'; require '../config/uploadDBconfig.php'; if (isset($_POST['delAccount'])){ $user = htmlspecialchars($_POST['user']); echo '<div class="alert alert-danger" role="alert">'; echo '<h2>Deleting '.$user; echo '</div>'; // Define SQL commands $sqlDelUp = 'DROP TABLE archivatoryUploads.'.$user.';'; $sqlDelUser = 'DELETE FROM archivatory.users WHERE username="'.$user.'";'; // Run SQL commads to delete user data $runDelUp = mysqli_query($link, $sqlDelUp); $runDelUser = mysqli_query($link, $sqlDelUser); // get and delete user profile photo $getProPho = shell_exec('ls ../uploads/profiles/ | grep '.$user); shell_exec('rm ../uploads/profiles/'.$getProPho); // Redirect upon success or output error message. if ($runDelUp) { if ($runDelUser) { header("Location: ../index.php"); } } else { echo 'Could not delete account. <br />'; echo $link->error; echo '<br /><br /> Please take a screen shot and send it to the #support thread on our <a href="https://discord.gg/PVNKWDx"> Discord chat</a>'; } } else { echo "Could not delete user content table. <br />"; echo $link->error; echo '<br /><br /> Please take a screen shot and send it to the #support thread on our <a href="https://discord.gg/PVNKWDx"> Discord chat</a>'; } include '../config/bottom.html'; ``` [Full source code found for execs/delUser.php at Github](https://github.com/jrswab/archivatory/blob/master/execs/delUser.php) ##### Updates to user content display page: ###### Show file size in MB: ``` while ($row = mysqli_fetch_assoc($result)) { echo '<tr><td>'.$row["date"].'</td><td>'.$row["file_name"].'</td> <td style="word-wrap:break-word"> <a href="https://ipfs.io/ipfs/'.$row["hash"].'" target="_blank">' .$row["hash"].'</a></td><td>'.$fileSize = ($row["file_size"]/1000000).' MB</td><td> ``` ###### Allow user to delete their files: ``` <div class="btn-group"> <img src="img/delete.png" width="50" type="button" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" /> <div class="dropdown-menu"> <a class="dropdown-item" name="id" href="?delete='.$row["id"].'">Yes, delete forever.</a> </div> </div></td></tr>'; } ``` ###### Check for _GET information to delete data. ``` //Check for deletion if (!empty($_GET['delete'])) { $sqlDelete = "DELETE FROM ".$_SESSION['username']." WHERE id='".$_GET["delete"]."'"; $delRun = mysqli_query($link, $sqlDelete); $rm = shell_exec("rm uploads/".$_GET['delete']); } ``` [Full source code found for hashtable.php at Github](https://github.com/jrswab/archivatory/blob/master/hash.php) #### GitHub Account https://github.com/jrswab ### Thanks For Reading! ###### All images came from royalty and attribution free sources unless specified. --- <center>Looking to take your Steem based creations to the next level? Join us over at the [Creators' Guild](https://discord.gg/YDcyTJR) Discord group! We are here to encourage, support and increase the creation of quality content. --- If you have any questions about the future of Steem or my witness please feel free to message `jrswab#3134` on Discord.  [Click here to vote with SteemConnect!](https://steemconnect.com/sign/account-witness-vote?witness=jrswab&approve=1) Or go to https://steemit.com/~witnesses You can see all active witnesses on @drakos' [steemian.info](https://steemian.info/witnesses) --- [Click here to join the mailing list and get exclusive SDB/STEEM giveaways!](http://eepurl.com/cUktFz) Looking to support my content creation efforts outside of the Steem Blockchain? Check out [jrswab.com/support](https://jrswab.com/support/) --- [Mastodon](https://mastodon.xyz/@jrswab) | [Keybase](https://keybase.io/jrswab) | [Twitter](https://twitter.com/jrswab) | [Gitlab](https://gitlab.com/jrswab) | [Hacker Culture Podcast](https://hackerculture.us)</center>
👍 patricklancaster, movement19, not-a-cat, evilest-fiend, creatorsguild, jennybeans, kslo, yuxi, blue-steens, ponpase, dreday20, kubbyelizabeth, sbi2, coincadet, laurabanfield, msp-waves, asbonclz, tailslide, sblue, halcyondaze, jasonbu, crimsonclad, discordiant, rodeo670, msp-lovebot, r351574nc3, salty-mcgriddles, lightabsolute, tamala, jackmillerbot, thanku, rival, omoyiwolabusayo, seanlloyd, isleofwrite, stever82, gmichelbkk, paulthebeloved, polbot, techslut, ubg, mstafford, uniwhisp, fundition, grzesiekb, ashwani-pratap, negativer, utopian-io, gladius, javiermurillo, juanwhite, tushantsingh, miguelalar, deathcloud, ravimudgal, moenawar, lulita, ebris, scottcbusiness,