CodeIgniter: how to capture images from a website and automatically download them to a folder

Source: Internet
Author: User
This article mainly introduces how CodeIgniter can capture images from websites and automatically download images to folders. The example analyzes the skills related to CodeIgniter webpage image operations, for more information about how CodeIgniter captures images from a website and automatically downloads them to a folder, see the following example. Share it with you for your reference. The details are as follows:

Because a website looks at a poor picture, it needs a one-page flip .... So .... I wrote something like this.

(I am a product rather than a programmer) the running speed is simply intolerable, and errors often occur, so I hope you can help improve (PHP ).

Of course, you are also welcome to see PYTHON and GOLANG versions ~~ Pai_^

1. controllers:

$ This-> load-> helper ('date'); $ this-> load-> helper ('phpquery'); // I put a single phpQuery file in helper.

2. view:

This is only for quick output of the product, so the code written directly in the VIEW should be ignored...

<? Php $ imageslist = phpQuery: newDocumentFile ('http: // g.e-hentai.org/xxxxx/xxxxxxx/'); // Home Page $ pn = 1; // page number $ ps = $ imageslist-> find ('. ptt td a'); // capture the page navigation from the homepage // Obtain the page content from the page navigation ($ ps as $ p) {echo 'quarter '. $ pn ++. 'page: attr ("href "). '"/>
'; $ Imagesnow = phpQuery: newDocumentFile (pq ($ p)-> attr ("href ")); // Single Page Content $ images = $ imagesnow-> find ('# gdt a'); // capture the image page list foreach ($ images as $ image) {echo 'attr ("href "). '"/>
'; $ Imagebig = phpQuery: newDocumentFile (pq ($ image, $ imagesnow)-> attr ("href ")); // Obtain the page address of a single image echo 'Find ('# i3 img')-> attr ('src '). '">
'; // Output image ob_start (); readfile ($ imagebig-> find (' # i3 img ')-> attr ('src ')); $ img = ob_get_contents (); ob_end_clean (); $ filename = 'IMG/'.now().'.jpg '; $ f = fopen ($ filename, 'A'); fwrite ($ f, $ img); fclose ($ f) ;}}?>

I hope this article will help you with CodeIgniter-based php programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.