将图像从 URL 保存到服务器
我使用 CKEditor 构建了一个小型内容管理系统。用户可以从其他网站粘贴图像 URL。有没有办法在用户提交内容时获取所有图像 URL,将所有这些图像保存到服务器,并用我的服务器的 URL 替换其他服务器的 URL?
例如,用户写了这样的内容:
<img src="somews.com/img1.jpg"/>Lorem Ipsum is simply dummy text of the printing and typesetting industry. ...
在提交过程中 PHP 会保存来自 < code>somews.com/img1.jpg 发送到服务器,将其 URL 转换为 myserver.com/photos/img1.jpg
并替换 与 .. 这可能吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的服务器上启用了 PHP5 和 HTTP 流包装器,则将其复制到本地文件非常简单:
copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg') ;
这将处理所需的任何管道等。如果您需要提供一些 HTTP 参数,您可以提供第三个“流上下文”参数。
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.