从URL将图像保存到服务器
I've built a mini-content management system with CKEditor. The user has the ability to paste an image URL from another website. Is there a way to to get all image URLs when the user submits the content, save all these images to the server, and replace another server's URL with URL of my server?
For example, the user wrote something like this:
<img src="somews.com/img1.jpg"/>Lorem Ipsum is simply dummy text of the printing and typesetting industry. ...
During the submit process PHP would save the image from somews.com/img1.jpg
to the server, converts its URL to myserver.com/photos/img1.jpg
and replaces <img src="somews.com/img1.jpg"/>
with .. Is that possible?
我用 CKEditor 。 用户可以从其他网站粘贴图像 URL 。 有没有办法在用户提交内容时获取所有图像URL,将所有这些图像保存到服务器,并用我的服务器的URL替换另一个服务器的URL? p>
例如,用户写了这样的内容: p>
&lt; img src =“somews.com/img1.jpg”/ &gt; Lorem Ipsum只是印刷和排版行业的虚拟文本。 ...
code> pre>
在提交过程中 PHP 将图像从 somews.com/img1.jpg code>保存到服务器,将其URL转换为 myserver.com/photos/img1.jpg code>并替换&lt; img src =“somews.com/img1.jpg”/&gt; code> with ..这可能吗? p>
div>
If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:
copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg');
This will take care of any pipelining etc. that's needed. If you need to provide some HTTP parameters there is a third 'stream context' parameter you can provide.