When copy & paste some news contains images from external web sites. Can FCKEditor upload these images to local server automaticly? That means it can upload the image "http://www.externalsites.com/xyz.jpg" to local server automaticly and change the image link in the saved content to local relative links.
I mean for the JSP project using FCKEditor. If the functionality is already there, how can we config it?
Thanks!
Min
I mean for the JSP project using FCKEditor. If the functionality is already there, how can we config it?
Thanks!
Min

Re: Auto upload remote sites' images to server?
Subscribing.
We have intranet website, our employees have limited access to the Internet. When a content manager posts news from external source via copy-paste, images are not uploaded automatically. We need this feature!
Re: Auto upload remote sites' images to server?
Here's a quick function in
Here's a quick function in php that does the trick. Sorry. I wrote this thing in a lost hour so there's no warranty and it may contain bugs or security issues. Comments are welcome.
Usage: $html = process_remote_images($html);
Considering that $html contains the response from CK Editor. That's all there is to is. Note that this string possibly needs to be stripslashed (depending on your php settings) and be addslashed again if you want to insert it in a sql database.
/* copies a remote image to the document root and returns the name in the /AutoImages/ folder that needs to exist in the web root. */ function download_image($image) { $ch = curl_init($image); if (!$ch) { die("Could not init curl."); } //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_HEADER, 1); $response = curl_exec($ch); if (!$response) { die("curl_exec error: ". curl_error($ch)); } // Then, after your curl_exec call: $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close($ch); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); if (!preg_match("/Content-Type: (.*)\r\n/i", $header, $match)) { die("No content type for image: $image."); } $type = $match[1]; switch (strtolower($type)) { case "image/gif": $ext = "gif"; break; case "image/jpg": case "image/jpeg": $ext = "jpg"; break; case "image/png": $ext = "png"; break; case "image/bmp": $ext = "bmp"; break; default: $ext = ""; die("Content-type: $type not supported."); break; } $rand = mt_rand(); $new = "/AutoImages/" . $rand . "." . $ext; $base = $_SERVER["DOCUMENT_ROOT"] . $new; $fp = fopen($base, "wb"); if (!$fp) { die("File: $base. Directory not writable."); } fwrite($fp, $body); fclose($fp); return $new; } /* searches the html for remote images and replaces them with a local copy */ function process_remote_images($html_content) { $base_url = "http://" . $_SERVER["SERVER_NAME"]; if (preg_match_all("/src=\"(https?:\\/\\/[^\"]+)\"/Ui", $html_content, $arr)) { $images = $arr[1]; foreach ($images as $image) { $image1 = html_entity_decode($image); if (strcasecmp($base_url, substr($image1, 0, strlen($base_url))) == 0) { /* the picture is already on our server */ continue; } $new = download_image($image1); $new = $base_url . $new; $html_content = str_ireplace($image, $new, $html_content); } } return $html_content; }Hello,
Hello,
Thanks chimit for this solution. I've tried and it works perfectly.
AnnaD