# Сайтуудаас Сэрвэрлүүгээ зураг татах

**URL:** <https://www.batmunkh.net/t/topic/239>\
**Category:** Tutorials, Solutions\
**Created:** [May 19, 2017, 8:09am UTC](https://www.batmunkh.net/t/topic/239 "2017-05-19T08:09:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankhbaatar](https://www.batmunkh.net/user_avatar/www.batmunkh.net/ankhbaatar/32/28_2.png) [@ankhbaatar](https://www.batmunkh.net/u/ankhbaatar)\
**Post date:** [May 19, 2017, 8:09am UTC](https://www.batmunkh.net/t/topic/239/1 "2017-05-19T08:09:34Z")

</div>

```
function grab_image($url,$saveto){
        $ch = curl_init ($url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
        $raw=curl_exec($ch);
        curl_close ($ch);
        if(file_exists($saveto)){
            unlink($saveto);
        }
        $fp = fopen($saveto,'x');
        fwrite($fp, $raw);
        fclose($fp);
    }
```

хэрэглэх заавар:

$url = ‘[http://example.com/graph.phpto=1491208200&id=187&from=1491179400&height=135&width=600](http://example.com/graph.phpto=1491208200&id=187&from=1491179400&height=135&width=600)’;  
$img = ‘/var/www/html/images/image.png’;  
grab\_image($url,$img);
