Ec (2); php saves remote images. I wrote this system myself, so I was quite paralyzed when uploading images. I also used a new cloud system, his editor supports remote image saving, but it is asp and my system only supports php. I think php may be easier to implement this function than asp, I started to think of using file_get_contents (), and then using fopen to save the content obtained by file_get_content. Here is a small program I implemented. & lt ;? Php $ f script ec (2); script
Php saves remote ImagesI wrote this system myself, so I was quite paralyzed when uploading images. I also used a new cloud system. His Editor supports the remote image saving function, but that is asp, and my system only supports php. I think php may be easier to implement this function than asp. I started to think of using file_get_contents (), then, use fopen to save the content obtained by file_get_content. Below is a small program I implemented.
$ Filed = "http://111cn.net/conference_php_quebec.gif ";
$ Datad = file_get_contents ($ filed );
$ Mydr = basename ($ file );
Fwrite (fopen ($ mydr, "wb +"), $ data );
?>
This is simple, but I think there is no implementation purpose, so I wrote the following code.
PHP code:
If ($ _ POST ['savepic '] = "checked "){
$ Img_array = array ();
$ Content1 = stripslashes ($ _ POST ['Post _ content']);
If (get_magic_quotes_gpc () $ content1 = stripslashes ($ content1 );
Preg_match_all ("/(src | SRC) = \" (http :\/\/(. + ). (gif | jpg | jpeg | bmp | png)/isU ", $ content1, $ img_array); // The regular expression starts matching all the images and puts them into the data.
$ Img_array = array_unique (dhtmlspecialchars ($ img_array [2]);
Print_r ($ img_array );
Set_time_limit (0 );
Foreach ($ img_array as $ key => $ value ){
$ Get_file = file_get_contents ($ value); // get the image
$ Filetime = time ();
$ Filepath = ".. /wp-content/uploads/pic2 /". date ("Y", $ filetime ). "/". date ("m", $ filetime ). "/"; // path directory of the saved Image
! Is_dir ($ filepath )? Mkdirs ($ filepath): null;
$ Filename = date ("YmdHis", $ filetime). random (1). '.'. substr ($ value,-3, 3 );
$ Fp = @ fopen ($ filepath. $ filename, "w ");
@ Fwrite ($ fp, $ get_file );
Fclose ($ fp); // finished, ha
$ Content1 = preg_replace ("/". addcslashes ($ value ,"/"). "/isU", "/wp-content/uploads/pic2 /". date ("Y", $ filetime ). "/". date ("m", $ filetime ). "/". $ filename, $ content1); // Replace the image address in the article by the way.
}
The above function saves all the images in your editor.