Created
May 31, 2009 18:12
-
-
Save shashi/120972 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* ppaste - Quick paste pictures anytime anywhere | |
* | |
* @author Bela Hausmann <[email protected]> | |
* @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