Skip to content

Instantly share code, notes, and snippets.

@shashi
Created May 31, 2009 18:13
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 shashi/120974 to your computer and use it in GitHub Desktop.
Save shashi/120974 to your computer and use it in GitHub Desktop.
Scripts for a free image hosting service
<?php
if(!@$PPASTE) die("Access Denied!");
$PPASTE_VERSION = '0.1_rc1';
$PPASTE_UPLOAD_DIR = 'p/';
$PPASTE_UPLOAD_URL = 'p/';
$PPASTE_CODE_LENGTH = 8;
$PPASTE_SHOW_TAIL = true;
$PPASTE_SHOW_FILETYPES = true;
$PPASTE_MAX_LIFE = 3000; //in minutes
/**
* check env
*/
is_dir($PPASTE_UPLOAD_DIR) or die('Please create upload directory: <code>mkdir /path/to/your/ppaste/install/<b>' . $PPASTE_UPLOAD_DIR . '</b></code>');
is_writable($PPASTE_UPLOAD_DIR) or die('Please make upload directory writable: <code>chmod 0777 /path/to/your/ppaste/install/<b>' . $PPASTE_UPLOAD_DIR . '</b></code>');
?>
<?php
/**
* ppaste::Cron - Performs Maintainance
*
* @author Shashi Gowda <connect2shashi@gmail.com>
* @link http://bitbucket.org/and3k/ppaste/
* @version 1.0_rc1
* @copyright Copyright (c) 2009 Bela Hausmann, see README
* @license http://opensource.org/licenses/agpl-v3.html GNU Affero General Public License version 3
*/
$PPASTE = true;
if(!(is_file('config.php') and include('config.php') )) die("No Config file \"config.php\"!");
/**
* main part
*/
function rec_delete ($dir,$reftime,$rmdir=false ) {
global $PPASTE_MAX_LIFE,$count;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($dir.'/'.$file)) rec_delete($dir.'/'.$file,$reftime,true);
elseif($reftime - filectime($dir.'/'.$file) > $PPASTE_MAX_LIFE*60)
if(unlink($dir.'/'.$file))
$count++;
}
}
closedir($handle);
}
if($rmdir && is_dir($dir)) rmdir($dir);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>ppaste</title>
<link rel="stylesheet" type="text/css" href="styles/colourful.css" />
</head>
<body>
<div id="body">
<h1>ppaste</h1>
<div id="content">
<?php
echo "<p>Scanning and cleaning up space... (This might take a while...)</p>";
$count=0;
rec_delete($PPASTE_UPLOAD_DIR,time());
echo "<p>Thanks for waiting, $count files were removed!</p>";
?>
</div>
</body>
</html>
<?php
/**
* ppaste - Quick paste pictures anytime anywhere
*
* @author Bela Hausmann <post@belahausmann.name>
* @link http://bitbucket.org/and3k/ppaste/
* @version 1.0_rc1
* @copyright Copyright (c) 2009 Bela Hausmann, see README
* @license http://opensource.org/licenses/agpl-v3.html GNU Affero General Public License version 3
*/
$PPASTE = true; // Do not change this!
if(!(is_file('config.php') and include('config.php') )) die("No Config file \"config.php\"!");
/**
* check env
*/
is_dir($PPASTE_UPLOAD_DIR) or die('Please create upload directory: <code>mkdir /path/to/your/ppaste/install/<b>' . $PPASTE_UPLOAD_DIR . '</b></code>');
is_writable($PPASTE_UPLOAD_DIR) or die('Please make upload directory writable: <code>chmod 0777 /path/to/your/ppaste/install/<b>' . $PPASTE_UPLOAD_DIR . '</b></code>');
/**
* main part
*/
#print_r($_FILES);
if(isset($_FILES['file']))
if($_FILES['file']['error'] === UPLOAD_ERR_OK
and getimagesize($_FILES['file']['tmp_name'])
and (
$_FILES['file']['type'] == 'image/jpeg'
or $_FILES['file']['type'] == 'image/png'
or $_FILES['file']['type'] == 'image/gif'
))
{
$code = '';
while(is_dir($PPASTE_UPLOAD_DIR . $code)) $code = substr(md5(rand()), 0, $PPASTE_CODE_LENGTH);
mkdir($PPASTE_UPLOAD_DIR . $code);
$filename = $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $PPASTE_UPLOAD_DIR . $code . '/' . $filename);
$link = $PPASTE_UPLOAD_URL . $code . '/' . $filename;
$message = array(
'class' => 'success',
'text' => 'Success: <a href="'.$link.'">Link to your picture</a>'
);
}
else
{
$message = array(
'class' => 'failure',
'text' => 'Picture upload failed'
);
}
else $message = null;
/**
* Output
*/
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>ppaste</title>
<link rel="stylesheet" type="text/css" href="styles/colourful.css" />
</head>
<body>
<div id="body">
<h1>ppaste</h1>
<div id="content">
<h2>Upload picture</h2>
<?php if($message) echo '<p class="'.$message['class'].'">'.$message['text'].'</p>' ?>
<form action="" method="post" enctype="multipart/form-data">
<p>
<input type="file" name="file" />
<input type="submit" name="upload" value="Upload" />
<?php if($PPASTE_SHOW_FILETYPES) { ?>
<br /><small>Allowed filetypes: JPEG, PNG, GIF</small>
<?php } ?>
</p>
</form>
<?php if(is_file('about.html')) echo file_get_contents('about.html') ?>
</div>
<?php if($PPASTE_SHOW_TAIL) { ?>
<div id="tail">
<p>
<a href="http://bitbucket.org/and3k/ppaste/">ppaste</a> v<?php echo $PPASTE_VERSION ?> - Quick paste pictures anytime anywhere - All pictures will be deleted after some time
</p>
</div>
<?php } ?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment