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 '
';
} else {
echo '
.$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="">
</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
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
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 '';
echo 'Deleting '
.$user;
echo '';
// 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.
';
echo $link->error;
echo '
Please take a screen shot and send it to the
#support thread on our
Discord chat';
}
} else {
echo "Could not delete user content table.
";
echo $link->error;
echo '
Please take a screen shot and send it to the
#support thread on our
Discord chat';
}
include '../config/bottom.html';
Full source code found for execs/delUser.php at Github
Updates to user content display page:
Show file size in MB:
while ($row = mysqli_fetch_assoc($result)) {
echo '' .$row["date"].'' .$row["file_name"].'
. $row["hash"].'" target="_blank">'
.$row["hash"].'' .$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
GitHub Account
Thanks For Reading!
All images came from royalty and attribution free sources unless specified.
Looking to take your Steem based creations to the next level?
Join us over at the Creators' Guild 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!
Or go to https://steemit.com/~witnesses
You can see all active witnesses on ' steemian.info
Click here to join the mailing list and get exclusive SDB/STEEM giveaways!
Looking to support my content creation efforts outside of the Steem Blockchain?
Check out jrswab.com/support
Mastodon | Keybase | Twitter | Gitlab | Hacker Culture Podcast