Пример #1
0
    hw_print_json_ajax($return_json);
    exit;
}
if (isset($_FILES['file'])) {
    $file = $_FILES['file'];
    //single file
    $filename = $file['tmp_name'];
    $name = basename($file["name"]);
    //file name
    $handle = fopen($filename, 'r');
    $data = fread($handle, filesize($filename));
    fclose($handle);
    $pvars = array('image' => base64_encode($data));
    //$image = file_get_contents($_FILES['file']['tmp_name']);
    $args = array('name' => $name, 'title' => $name);
    $reply = HW_IMGUR::upload_image2album(base64_encode($data), HW_IMGUR::main_album, $args);
    /*
    	$client_id = "9b5122a3d34e478";
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
    	curl_setopt($ch, CURLOPT_POST, TRUE);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    	curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Client-ID ' . $client_id ));
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $pvars );
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    	curl_setopt($ch, CURLOPT_TIMEOUT, 100);
    
    	$reply = curl_exec($ch);
    	curl_close($ch);
    
Пример #2
0
        if ($action == 'load_images') {
            $album = isset($_POST['al']) ? $_POST['al'] : 'bld18';
            //or get default album
            $images = HW_IMGUR::get_images_album($album);
            $result = array();
            //$html = '<div class="album-images">';
            //catch error if imgur token expire
            if (isset($images->error)) {
                $return['result'] = 'error';
                $return['error'] = 1;
                $return['message'] = $images->message;
            } elseif (is_array($images)) {
                foreach ($images as $img) {
                    //$html .= '<div class="image-item" id="'. $img->id .'"><img class="thumb" src="'.$img->link. '"/></div>';
                    if (!is_object($img) && !is_array($img)) {
                        continue;
                    }
                    $result[] = array('link' => $img->link, 'id' => $img->id, 'title' => $img->title, 'description' => $img->description);
                }
                $return['result'] = 'success';
                $return['data'] = $result;
            }
            //$html .= '</div>';
            hw_print_json_ajax($return);
        } elseif ($action == 'valid_session') {
            //valid token if expire then create new one
            HW_IMGUR::get_token();
            hw_print_json_ajax(array('result' => 'done', 'error' => 0, 'message' => ''));
        }
    }
}
 public static function init()
 {
     self::$imgur_authorize = str_replace('{client_id}', self::client_id, self::$imgur_authorize);
 }