0

我有一张来自这个链接的图片。我想把它复制到我的服务器上。这是我尝试过的:

$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; 
   }      

不过,上述方法不起作用。

这也不起作用:

$input = $url;
$output = 'imageimage.jpg';
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/upload/1/',$output, file_get_contents($input));
4

1 回答 1

-1

777 文件夹权限,对我有用。

于 2016-07-31T10:56:44.530 回答