Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. if (preg_match("/http/",$url_files)){
  2. $ch = curl_init($url_files);
  3. curl_setopt($ch, CURLOPT_HEADER, 0);
  4. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  6. $out = curl_exec($ch);
  7. $image_sv = 'путь_куда_вы_сохраняете_картинку'.$nm.'.jpg';
  8. $img_sc = file_put_contents($image_sv, $out);
  9. curl_close($ch);
  10. }
  11.  
  12. function grab_image($url,$saveto){
  13. $ch = curl_init ($url);
  14. curl_setopt($ch, CURLOPT_HEADER, 0);
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  17. $raw=curl_exec($ch);
  18. curl_close ($ch);
  19. if(file_exists($saveto)){
  20. unlink($saveto);
  21. }
  22. $fp = fopen($saveto,'x');
  23. fwrite($fp, $raw);
  24. fclose($fp);
  25. }
  26.  
  27. use MCurlClient;
  28.  
  29. $urls = array(
  30. 'ht tp://cs1-38v4.vk-cdn.net/p13/cdfeaeaf00705d.mp3',
  31. 'ht tp://cs1-32v4.vk-cdn.net/p2/5c0972b283ee17.mp3',
  32. );
  33. $save_path = '/tmp';
  34.  
  35. $client = new Client();
  36.  
  37. do {
  38. while ($client->has()) {
  39. $result = $client->next();
  40. // Пересохраняем рисунок с ошибкой
  41. if ($result->hasError()) {
  42. $urls[] = $result->options[CURLOPT_URL];
  43. }
  44. }
  45.  
  46. foreach($urls as $url) {
  47. $file = $save_path . '/'. basename($url);
  48. $client->add([
  49. CURLOPT_URL => $url,
  50. CURLOPT_FILE => fopen($file, 'w'),
  51. ]);
  52. }
  53. $urls = [];
  54.  
  55. } while($client->run() || $client->has());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement