Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created December 20, 2011 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/1502840 to your computer and use it in GitHub Desktop.
Save rlemon/1502840 to your computer and use it in GitHub Desktop.
public_files
<?php
/* Public files - accessible from http://rlemon.com/public_files/ */
if( isset($_GET['download']) ) {
if( file_exists($_GET['download']) ) {
$file = $_GET['download'];
header('Cache-Control: public');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=$file');
header('Content-Type: application/zip');
header('Content-Transfer-Encoding: binary');
readfile($file);
} else {
die('Error! The file "' . $_GET['download'] . '" does not exist! <a href=".">Click to go back</a>');
}
}
?>
<html><head><title>rlemon.com public files</title>
<style>
/* Normalize */
body,html {
width: 100%;
}
body,ul,li {
margin:0;
padding:0;
}
ul {
list-style:none;
}
ul, h1, p {
width: 600px;
margin: 0 auto;
}
ul {
background-color: #efefef;
border: 1px solid #999;
border-bottom: none;
}
ul li {
border-bottom: 1px solid #999;
padding: 3px;
}
ul li:nth-child(odd) {
background-color: #e6e6e6;
}
ul li a {
float: right;
}
ul li a, p {
padding: 0 3px;
}
p {
color: #900;
font-size: 150%;
font-weight: 700;
}
a:link {
text-decoration: none;
color: #00a;
}
a:visited {
text-decoration: none;
color: #a0a;
}
a:active {
color: #aa0;
}
a:hover {
color: #a00;
}
</style>
</head><body>
<h1>rlemon.com public_files</h1>
<ul>
<?php
$handle = opendir('.');
while( ($item = readdir($handle)) !== false ) {
if( !is_dir($item) && $item !== '.' && $item !== '..' && substr($item, 0, 1) !== '.' && $item !== 'index.php' ) {
echo <<<EOT
<li>
<span>{$item}</span>
<a href='?download={$item}'>Download</a>
<a href='{$item}'>View</a>
</li>
EOT;
}
}
?>
</ul>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment