Last active
August 29, 2015 14:21
-
-
Save TheBITLINK/70dd16557c3f69f5e65f to your computer and use it in GitHub Desktop.
This PHP script displays the last image uploaded to the server, simply. When somebody uploads an image, the next visitor (or person who reloads the page) will see that image. It was made Just For Fun, and you can do anything with the code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$html = '<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Latest Uploaded Image</title> | |
<meta charset="utf-8"> | |
<meta property="og:title" content="Latest Uploaded Image" /> | |
<meta property="og:type" content="website" /> | |
<meta property="og:description" content="It shows the last image uploaded. | |
Upload your own image and give a surprise to the next visitor." /> | |
<style> | |
@font-face { | |
font-family: "Segoe UI"; | |
font-weight: 200; | |
src: local("Segoe UI Light"); | |
} | |
@font-face { | |
font-family: "Segoe UI"; | |
font-weight: 300; | |
src: local("Segoe UI Semilight"); | |
} | |
@font-face { | |
font-family: "Segoe UI"; | |
font-weight: 400; | |
src: local("Segoe UI"); | |
} | |
@font-face { | |
font-family: "Segoe UI"; | |
font-weight: 600; | |
src: local("Segoe UI Semibold"); | |
} | |
@font-face { | |
font-family: "Segoe UI"; | |
font-weight: 700; | |
src: local("Segoe UI Bold"); | |
} | |
@font-face { | |
font-family: "Segoe UI"; | |
font-style: italic; | |
font-weight: 400; | |
src: local("Segoe UI Italic"); | |
} | |
@font-face { | |
font-family: "Segoe UI"; | |
font-style: italic; | |
font-weight: 700; | |
src: local("Segoe UI Bold Italic"); | |
} | |
body{ | |
background: #000000 url(\'./?mode=img&ts='.time().'\') no-repeat fixed center center; | |
background-size: contain; | |
font-family: "Segoe UI"; | |
} | |
#topBar{ | |
position: fixed; | |
top: 0; | |
z-index: 2; | |
width: 100%; | |
background: rgba(66,66,66,.5); | |
height: 42px; | |
margin: 0; | |
left: 0; | |
} | |
#topBar span | |
{ | |
font-size: 28px; | |
padding-left: 16px; | |
} | |
a, span | |
{ | |
text-decoration: none; | |
color: #ffffff!important; | |
font-weight: 100; | |
} | |
#mahFrm{ | |
display: none; | |
} | |
#uplBtn | |
{ | |
float: right; | |
height: 100%; | |
margin: 0; | |
color: #FFF; | |
color: #FFF; | |
background-color: rgba(255, 255, 255, 0.2); | |
border-color: transparent; | |
color: #fff; | |
border-style: solid; | |
padding: 4px 8px; | |
border-width: 2px; | |
background-clip: border-box; | |
border-radius: 0px; | |
font-size: 15px; | |
font-weight: 400; | |
line-height: 1.333; | |
} | |
#uplBtn:hover | |
{ | |
border-color: rgba(255, 255, 255, 0.4); | |
} | |
@keyframes outanm { | |
from { | |
opacity: 1; | |
animation-timing-function: ease; | |
transform: scale(1); | |
} | |
to { | |
opacity: 0; | |
animation-timing-function: ease; | |
transform: scale(0.5); | |
} | |
} | |
#pf5 | |
{ | |
animation-delay: 2s; | |
animation-duration: 0.5s; | |
animation-name: outanm; | |
animation-fill-mode: forwards; | |
text-align: center; | |
position: fixed; | |
bottom: 10%; | |
width: 100%; | |
} | |
#pf5 span | |
{ | |
background-color: rgba(0, 0, 0, .5); | |
border-color: transparent; | |
color: #fff; | |
font-size: 2em; | |
border-radius: 5px; | |
padding: 8px; | |
font-weight: 100; | |
} | |
@media only screen and (max-width: 720px) { | |
hdm{ display:none; } | |
#pf5 span {font-size: 1em;} | |
} | |
@media only screen and (max-width: 480px) { | |
hds,hdm{ display:none; } | |
#pf5 span {font-size: 1em;} | |
} | |
</style> | |
<script> | |
(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,\'script\',\'//www.google-analytics.com/analytics.js\',\'ga\'); | |
ga(\'create\', \'UA-63061236-1\', \'auto\'); | |
ga(\'send\', \'pageview\'); | |
</script> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | |
</head> | |
<body oncontextmenu="return false"> | |
<div id="topBar"> | |
<span><a href=".">Last Image<hds> Uploaded</hds></a></a><a href="https://gist.github.com/TheBITLINK/70dd16557c3f69f5e65f"> <i class="fa fa-github"></i></a></span> | |
<form id="mahFrm" method="post" action="./" enctype="multipart/form-data"> | |
<input type="hidden" name="mode" value="upl"></input> | |
<input type="file" id="imgu" name="img"></input> | |
<input type="submit" id="smu"></input> | |
</form> | |
<button id="uplBtn"><hdm>Upload new image</hdm> <i class="fa fa-upload"></i> </button> | |
<script> | |
document.getElementById("uplBtn").onclick = function(){ | |
document.getElementById("imgu").click(); | |
} | |
document.getElementById("imgu").onchange = function(){ | |
document.getElementById("smu").click(); | |
} | |
</script> | |
</div> | |
<div id="pf5"><span>Press F5 to Reload</span></div> | |
</body> | |
</html>'; | |
if(empty($_REQUEST['mode'])){ | |
echo $html; | |
} | |
if($_REQUEST['mode'] == 'upl') | |
{ | |
$tf = './' . basename($_FILES["img"]["name"]); | |
$ft = strtolower(pathinfo($tf,PATHINFO_EXTENSION)); | |
$tf2 = $tf = './image.' . $ft; | |
if($ft != "jpg" && $ft != "png" && $ft != "jpeg" && $ft != "gif" && $ft != "svg" ) { | |
echo '<script>alert("Invalid File Extension");</script>'; | |
die($html); | |
} | |
if(!getimagesize($_FILES["img"]["tmp_name"])) { | |
echo '<script>alert("It looks like You Didn't upload an image.");</script>'; | |
die($html); | |
} | |
if ($_FILES["img"]["size"] > 2097152) { | |
echo '<script>alert("The image can't be bigger than 2mb");</script>'; | |
die($html); | |
} | |
move_uploaded_file($_FILES["img"]["tmp_name"], $tf2); | |
header('Location: https://d.thebit.link/r/'); | |
} | |
if($_REQUEST['mode'] == 'img') | |
{ | |
$files = glob("*.{png,jpg,gif,svg}", GLOB_BRACE); | |
$files = array_combine($files, array_map("filemtime", $files)); | |
arsort($files); | |
$newest_file = key($files); | |
header('Content-Type: image/'.pathinfo($newest_file,PATHINFO_EXTENSION)); | |
echo file_get_contents($newest_file); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment