PHP Save the remote picture , I This system is written by myself, so upload the picture when quite paralyzed, I also used a new cloud of a system, he that editor support remote save picture function, But that's ASP and my system only supports PHP I think PHP may be easier than the ASP to implement this function, began to think with file_get_contents (), and then use fopen to save file_get_content get content on the OK, Here is a small program that I have implemented.
<?php
$filed = "Yun_qi_img/conference_php_quebec.gif";
$datad =file_get_contents ($filed);
$mydr =basename ($file);
Fwrite (fopen ($mydr, "wb+"), $data);
?>
It's easy, but I don't think it's going to happen. So I wrote the following code
PHP Code:
if ($_post[' savepic ']== "checked") {
$img _array = Array ();
$content 1 = stripslashes ($_post[' post_content '));
if (GET_MAGIC_QUOTES_GPC ()) $content 1 = stripslashes ($content 1);
Preg_match_all ("/(src| SRC) =\ "(http:\/\/(. +). ( gif|jpg|jpeg|bmp|png))/isu ", $content 1, $img _array);//start matching all pictures and put 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);//start getting pictures now OH
$filetime = time ();
$filepath = ". /wp-content/uploads/pic2/". Date (" Y ", $filetime)." /". Date (" M ", $filetime)." /";//Picture Saved path directory
!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
$content 1 = preg_replace ("/". Addcslashes ($value, "/"). " /isu ","/wp-content/uploads/pic2/". Date (" Y ", $filetime)." /". Date (" M ", $filetime)." /". $filename, $content 1); By the way, replace the picture address inside the article
}
The above function realizes that all the pictures in your editor are saved.