0

I've an image from this link. I want to copy it to my server. This is what I've tried:

$url = 'http://tex.z-dn.net/?f=4%5E%7B13%7D%2A2%5E%7B-10%7D%3A16%5E%7B3%7D ';

   function GetImageByURL($url, $path = null) { 
      $opts = array(CURLOPT_URL => $url, 
                    CURLOPT_HEADER => false, 
                    CURLOPT_RETURNTRANSFER => true, 
                    CURLOPT_TIMEOUT => 10); 
      $ch = curl_init(); 
      curl_setopt_array($ch, $opts); 
      $result = curl_exec($ch); 
      if (   (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200 
          && (strpos(curl_getinfo($ch, CURLINFO_CONTENT_TYPE), "image") !== false))) 
      { 
        $name = substr($url, strrpos($url, '/')+1); 
        if ($path) { 
          if (is_writeable($path)) 
            file_put_contents(rtrim($path, '/') . '/' . $name, $result); 
          echo $result;
        } else {
          echo "error : {$path}"; 
        } 
        return $name; 
      } 
      curl_close($ch); 
      return false; 
   }      

The above doesn't work, though.

This also doesn't work:

$input = $url;
$output = 'imageimage.jpg';
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/upload/1/',$output, file_get_contents($input));
Phiter
  • 14,570
  • 14
  • 50
  • 84
Art Noimann
  • 115
  • 3
  • Do you have enough permissions to write to a folder? – u_mulder Feb 17 '16 at 20:13
  • 4
    Tell us what error it throws. – phaberest Feb 17 '16 at 20:18
  • How are you calling `GetImageByUrl`? What are you passing to the `$path` parameter? Note, too, that this function can return `false` or a string, and that if it succeeds you won't close the curl call. You have some significant problems here. – Nathaniel Ford Feb 17 '16 at 21:03
  • First exapmle, incorrect function: `is_writeable`. Second exapmle: incorrect arguments (scond argument filename, but should be content) – Dmytro Feb 19 '16 at 21:24

1 Answers1

-1

777 Permission to the Folder, works for me.