<? Php
//
// Function: Obtain the remote image and save it to the local device.
//
//
// Make sure you have the permission to write files to the local server
//
//
// Variable description:
// $ Url is the complete URL of the remote image. It cannot be blank.
// $ Filename is an optional variable. If it is null, the local file name is based on the time and date.
// Automatically generated.
Function GrabImage ($ url, $ filename = ""){
If ($ url = ""): return false; endif;
If ($ filename = ""){
$ Ext = strrchr ($ url ,".");
If ($ ext! = ". Gif" & $ ext! = ". Jpg"): return false; endif;
$ Filename = date ("dMYHis"). $ ext;
}
Ob_start ();
Readfile ($ url );
$ Img = ob_get_contents ();
Ob_end_clean ();
$ Size = strlen ($ img );
$ Fp2 = @ fopen ($ filename, "");
Fwrite ($ fp2, $ img );
Fclose ($ fp2 );
Return $ filename;
}
$ Img = GrabImage ("http://news.bbc.co.uk/images/_1978837_detector_ap100.jpg ","");
If ($ img): echo '<pre> </pre> ';
Else: echo "false ";
Endif;
?>