Public paste
Undefined
By: PnE | Date: Oct 8 2008 19:34 | Format: PHP | Expires: never | Size: 1.37 KB | Hits: 1801

  1. <?php
  2.  
  3. // Initiera Curl
  4. $curl = curl_init();
  5.  
  6. // Användare osv..
  7. $user = "demo";
  8. $password = "";
  9.  
  10.  
  11. //Storlek på filen
  12. $size = filesize($filename);
  13.  
  14.  
  15. // Den DAV-enablade URLen till att hämta ifrån
  16.  
  17. $url = "http://lan:85/cgi-bin/video.jpg?size=3";
  18.  
  19.  
  20. // Göra så att cURL fattar allt den ska göra
  21. // ladda in destinationen i cURL
  22.  
  23. curl_setopt($curl,CURLOPT_URL,$url);
  24.  
  25. // Säga att vi gör en PUT.
  26.  
  27. curl_setopt($curl,CURLOPT_PUT,true);
  28.  
  29. // Uppfatta och presentera filstorleken som vi kör PUT på
  30.  
  31. curl_setopt($curl,CURLOPT_INFILESIZE,$size);
  32.  
  33.  
  34. // Sätta en user-agent
  35.  
  36. curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/4.0");
  37.  
  38.  
  39. // Stoppa in namn och lösen
  40.  
  41. if(!empty($user) && !empty($password))
  42.  
  43.     curl_setopt($curl,CURLOPT_USERPWD,$user . ":" . $password);
  44.  
  45. // Utifall du kommer använda SSL och inte vill betala för nått riktigt
  46.  
  47.  
  48. if(ereg("^(https)",$url))
  49.     curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
  50.  
  51. // Kör och logga i curl_put.log
  52.  
  53. $result = curl_exec($curl);
  54. $error = curl_error($curl);
  55.  
  56. if(empty($error))
  57.  
  58.     list($return,,$message) = split("(r?n){1,}",trim(strip_tags($result)));
  59.  
  60. else {
  61.  
  62.     $return = "Error";
  63.  
  64.     $message = curl_error();
  65.  
  66. }
  67.  
  68.  
  69.  
  70. $log = fopen('curl_put.log','a');
  71.  
  72.  
  73.  
  74. fwrite($log,date("r - ") . $return . "rn" . $message . "rnrn");
  75.  
  76.  
  77. // Städa upp!
  78.  
  79. fclose($log);
  80. curl_close($curl);
  81.  
  82.  
  83. ?>