Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* _____ _____ _ _____ _____ _____ _____ _____ _____
- ___| | __ |_| _ |_ _|___ ___|_ _| __| _ | |
- |_ -| --| -| | __| | | |- _|___| | | | __| | | | |
- |___|_____|__|__|_|__| |_| |___| |_| |_____|__|__|_|_|_|
- |s C R i P T z - T E A M . i N F O|----------------------------
- [PHP] ImgUr Uploader
- */
- error_reporting(0);
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>ImgUr Uploader</title>
- <style type="text/css">
- html {
- background: #f1f1f1;
- }
- a {
- color: #5783ad;
- }
- body {
- background: #fff;
- margin: 22px auto;
- width: 764px;
- padding: 22px;
- text-align: center;
- font-family: Georgia, "Times New Roman", Times, serif;
- color: #464646;
- }
- h2 {
- font-size: 3em;
- font-weight: normal;
- }
- #green_box {
- background: none repeat scroll 0 0 #D5E7C8;
- border: 1px solid #A4D083;
- color: #4E8426;
- font-size: 11px;
- line-height: 190%;
- margin-bottom: 5px;
- padding: 8px;
- }
- #red_box {
- background: none repeat scroll 0 0 #F3E3E6;
- border: 1px solid #E599AA;
- color: #80001C;
- font-size: 11px;
- line-height: 190%;
- margin-bottom: 5px;
- padding: 8px;
- }
- #big {
- font-size: 20px;
- font-weight: bold;
- font-family: Calibri,Verdana;
- }
- </style>
- </head>
- <body>
- <h2>ImgUr Uploader</h2>
- <div id="content" align="center">
- <?php
- if (isset($_FILES['userfile']) && $_FILES['userfile'] != "") {
- $api_key = "37fa9221ba13d0f9050ece201934238f";
- $file = getcwd() . '/' . basename($_FILES['userfile']['name']);
- move_uploaded_file($_FILES['userfile']['tmp_name'], $file);
- list($width, $height, $file_type) = getimagesize($file);
- if ($file_type == 3) {
- $image = imagecreatefrompng($file);
- imagealphablending($image, false);
- imagesavealpha($image, true);
- ob_start();
- imagepng($image);
- $data = ob_get_contents();
- ob_end_clean();
- }
- if ($file_type == 2) {
- $image = imagecreatefromjpeg($file);
- imagealphablending($image, false);
- imagesavealpha($image, true);
- ob_start();
- imagejpeg($image);
- $data = ob_get_contents();
- ob_end_clean();
- }
- if ($file_type == 1) {
- $image = imagecreatefromgif($file);
- imagealphablending($image, false);
- imagesavealpha($image, true);
- ob_start();
- imagegif($image);
- $data = ob_get_contents();
- ob_end_clean();
- }
- $pvars = array(
- 'image' => base64_encode($data),
- 'key' => $api_key
- );
- $timeout = 30;
- $curl = curl_init();
- $post = http_build_query($pvars);
- curl_setopt($curl, CURLOPT_URL, 'http://imgur.com/api/upload.xml');
- curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
- curl_setopt($curl, CURLOPT_HTTPHEADER, array(
- "Content-type: application/x-www-form-urlencoded"
- ));
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- $xml_raw = curl_exec($curl);
- curl_close($curl);
- unlink($file);
- $xml = new SimpleXMLElement($xml_raw);
- if ($xml->error_code != '') {
- $imgur_error_code = $xml->error_code;
- $imgur_error_msg = $xml->error_msg;
- settype($imgur_error_code, "string");
- settype($imgur_error_msg, "string");
- echo '<div id="red_box"><h1>Error #' . $imgur_error_code . ', ' . $imgur_error_msg . '</h1></div>';
- die();
- } else {
- imagedestroy($image);
- $imgur_original = $xml->original_image;
- $imgur_large_tbn = $xml->large_thumbnail;
- $imgur_small_tbn = $xml->small_thumbnail;
- $imgur_image_hash = $xml->image_hash;
- $imgur_delete_hash = $xml->delete_hash;
- $imgur_page = $xml->imgur_page;
- $img_delete_page = $xml->delete_page;
- settype($imgur_original, "string");
- settype($imgur_large_tbn, "string");
- settype($imgur_small_tbn, "string");
- ?>
- <div id="green_box">
- <div align="center">
- <div id="insert_box_img">
- <h1>Small thumbnail :</h1>
- <img src="<?php
- echo $imgur_small_tbn;
- ?>" border="0" />
- <h1>Large thumbnail :</h1>
- <img src="<?php
- echo $imgur_large_tbn;
- ?>" border="0" />
- </div>
- </div>
- </div>
- <?php
- }
- die();
- }
- ?>
- <form enctype="multipart/form-data" action="" method="POST">
- Image: <input name="userfile" type="file" id="big"/>
- <input type="submit" value="Upload" id="big"/>
- </form>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment