public
Last active

Scripts for a free image hosting service

  • Download Gist
config.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?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>');
?>
cron.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<?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>
ppaste.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
<?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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.