1

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?

4
  • Parse the submitted HTML, extract image URLs, download the images, store them, update the image URLs in the HTML. Done. Commented Oct 10, 2011 at 9:48
  • possible duplicate of Best methods to parse HTML with PHP, save image from php url using php Commented Oct 10, 2011 at 9:49
  • it's simple for you. but how to do that? Commented Oct 10, 2011 at 9:49
  • I added you some duplicate questions, you should use the search before posting a new, combined question. Commented Oct 10, 2011 at 9:50

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

how to parse html for all image urls, do this, and convert results all urls
check here to parse html for image url web-development-blog.com/archives/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.