Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$t=curl_multi_getcontent ($ch);
- //list($header, $data) = explode("\n\n", $s4, 2);
- session_start();
- if (!isset($_POST['ajax'])) {
- draw_page();
- exit();
- }
- if (isset($_POST['url'])) {
- if ($_POST['url']=='') {
- show_test();
- exit();
- }
- show_image($_POST['url']);
- }
- if (isset($_POST['status'])) {
- echo 'url: '.@$_SESSION['url'].'<br/>getheader: '.@$_SESSION['getheader'].'<br/>'.
- @$_SESSION['status'];
- exit();
- }
- //--------------------------------------------
- function show_image($link) {
- get_allheaders($link);
- echo 'avail= '.check_avail($link).'<br/>';
- echo 'is image= '.check_image($link).'<br/>';
- echo '<img src="'.load_image($link).'" width="400px" /><br/>';
- }
- //--------------------------------------------
- function show_test() {
- $links = array("test.jpg");
- foreach ($links as $link) {
- get_allheaders($link);
- echo 'avail= '.check_avail($link).'<br/>';
- echo 'is image= '.check_image($link).'<br/>';
- echo '<img src="'.load_image($link).'" width="400px" /><br/>';
- }
- }
- //--------------------------------------------
- function draw_page() {
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>curl examples</title>
- <script type="text/javascript" src="jquery.min.js"></script>
- <script type="text/javascript">
- var st, targ;
- //----------------------------------------
- function onBeforeSend(xhr, settings) {
- st.html('loading...please wait');
- }
- //----------------------------------------
- function onSuccess(inf, status, xhr) {
- targ.html(inf);
- }
- //----------------------------------------
- function onError(xhr, status, exception) {
- targ.html('error occured<br/>status:'+status+'<br/>exception:'+exception);
- }
- //----------------------------------------
- function onComplete (xhr, status) {
- st.html('request completed, status:'+status);
- clearInterval(infoo);
- }
- //----------------------------------------
- $(document).ready (
- function() {
- st = $('#status');
- targ = $('#ajax');
- $('form[name=zz]').submit(
- function() {
- $.ajax ({
- type:'POST',
- url: location.href,
- data: {
- ajax:'',url: this.url.value
- },
- beforeSend: onBeforeSend,
- success: onSuccess,
- error: onError,
- complete: onComplete
- });
- window.infoo = setInterval ( function() {
- $.ajax ({
- type:'POST',
- url: "stat88.php",
- data: {
- ajax:'',status:''
- },
- success: function(inf) {
- $('#curlstatus').html(inf);
- },
- });
- }, 1000);
- return false;
- });
- } )
- </script>
- <style type="text/css">
- * {
- margin:0;
- padding:0;
- }
- body {
- font-family: verdana, sans-serif;
- font-size: 1em;
- }
- #frm {
- float:left;
- width:400px;
- border: solid 1px #999;
- padding: 20px;
- }
- #rez {
- margin-left:450px;
- }
- #status {
- height: 10px;
- border: solid 1px #800;
- padding: 10px;
- }
- #ajax {
- border: solid 1px #999;
- padding: 10px;
- }
- #curlstatus {
- font-size: 12px;
- word-wrap: break-word;
- }
- </style>
- </head>
- <body>
- <div id="frm">
- <form name="zz" enctype="application/x-www-form-urlencoded">
- <p>input url:
- <input type="text" name="url" size="50" /></p>
- <input type="submit" value="send" />
- </form>
- <div id="curlstatus">
- </div>
- </div>
- <div id="rez">
- <div id="status"></div>
- <div id="ajax"</div>
- </div>
- </body>
- </html>
- <?php
- }
- //---------------------------------------------
- function load_image($url) {
- $s = get_url($url);
- return 'data:image/jpeg;base64,'.base64_encode($s);
- }
- //---------------------------------------------
- function check_avail($url) {
- $s = get_url($url, true);
- return $s['http_code']==200;
- }
- //---------------------------------------------
- function check_image($url) {
- $s = get_url($url, true);
- return (substr($s['content_type'],'image')!=-1) || $s['content_type']=='application/octet-stream';
- }
- //---------------------------------------------
- function get_allheaders($url) {
- $s = get_url($url, true);
- echo '<pre>'.print_r($s,true).'</pre><br/>';
- }
- //---------------------------------------------
- function callback($download_size, $downloaded, $upload_size, $uploaded)
- {
- session_start();
- $_SESSION['status']= 'download size: '.$download_size.'<br/>downloaded: '.$downloaded.
- '<br/>upload size:'.$upload_size.'<br/>uploaded: '.$uploaded.'<br/>';
- session_write_close();
- }
- //---------------------------------------------
- function get_url($url, $header=0) {
- $_SESSION['url']=$url;
- $_SESSION['getheader']=$header;
- $_SESSION['status']='started<br/>';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_NOPROGRESS, false);
- curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'callback');
- curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
- curl_setopt($ch, CURLOPT_HEADER, $header);
- curl_setopt ($ch, CURLOPT_NOBODY, $header);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_USERAGENT,
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch,CURLOPT_ENCODING, 1);
- session_write_close();
- $s4 = curl_exec($ch);
- $s = curl_getinfo($ch);
- if (curl_errno($ch)) {
- throw new Exception ('curl exception: '.curl_error($ch));
- }
- curl_close($ch);
- session_start();
- if ($header==1)
- return $s;
- else
- return $s4;
- }
- ?>
Add Comment
Please, Sign In to add comment