views:

29

answers:

0

I need to modify this simple script, have searched the web for hours but getting nowhere with it.

What I need to do is firstly fetch the url to be used from either a text file on my site or from a decoded json output - such as "$FullPicURL = "http://somesite.com" . $data[2];" or "file_put_contents($image, file_get_contents("http://somesite.com/" . $path->url));" or similar...

and also rename the image file saved to my site to something like "testimage.png", so that each time I grab the image, it overwrites the old image.

Appreciate any help with this.

$img[]='http://somesite.com/sample.png';  
foreach($img as $i){  
                save_image($i);  

}

function save_image($img,$fullpath='basename'){  
                if($fullpath=='basename'){  
                $fullpath = basename($img);  
            }  
            $ch = curl_init ($img);  
            curl_setopt($ch, CURLOPT_HEADER, 0);  
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
            curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);  
            $rawdata=curl_exec($ch);  
            curl_close ($ch);  
            if(file_exists($fullpath)){  
                unlink($fullpath);  
            }  
            $fp = fopen($fullpath,'x');  
            fwrite($fp, $rawdata);  
            fclose($fp);  
}