PHP code for downloading remote files to local storage
- Function GrabImage ($ url, $ filename = ""){
- If ($ url = "") return false;
- If ($ filename = ""){
- $ Ext = strrchr ($ url ,".");
- If ($ ext! = ". Gif" & $ ext! = ". Jpg") return false;
- $ 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;
- }
- Function gethttpimage ($ url ){
- If (! Empty ($ url )){
- $ Filename = uniqid (). strrchr ($ url ,".");
- Echo $ filename;
- $ Get_file = @ file_get_contents ($ url );
- If ($ get_file ){
- $ Fp = @ fopen ($ filename, "w ");
- @ Fwrite ($ fp, $ get_file );
- @ Fclose ($ fp );
- }
- Return $ imgUrl;
- } Else {
- Return false;
- }
- }
- // $ Img = GrabImage ("http://img.it-home.org/data/attachment/forum/2016pic1/error_link.gif ","");
- $ Img = gethttpimage ("http://img.it-home.org/data/attachment/forum/2016pic1/error_link.gif ","");
- If ($ img) echo'';
- Else echo "false ";
- ?>
|
PHP