A simple php image collection program

Source: Internet
Author: User
The PHP collection of a single file saves the collected id data to a txt file, and runs the php file to automatically run the collection, mainly to understand a collection principle of PHP, it is not suitable for direct website application. this program is a program that collects beautiful pictures of the world's mm Forum. this file uses the ID of the target website after opening and collecting the website, then, save the ID to the txt file, and form a set of PHP collections that collect a single file in the txt file. then, save the collected id data to a txt file, you can run the php file to automatically run the collection. it is mainly to understand a collection principle of php and is not suitable for direct website applications. this program is a program for collecting beautiful pictures on the mm Forum, this file uses open the target website address, collect the ID of the website address, and save the ID to the txt document. in the txt document, a set of collected IDs are formed, we can use this program to collect an ID from other websites, and then use the principle of single file collection for warehouse receiving, but this file needs to be modified as appropriate.

The following is the source file:

PHP code
  1. Session_start ();
  2. $ T = time ();
  3. $ Arr = explode ("\ n", file_get_contents ("a.txt "));
  4. $ Id =! Isset ($ _ GET ['id'])? 0: trim ($ _ GET ['id']);
  5. $ Tid = trim ($ arr [$ id]);
  6. If (! Isset ($ _ SESSION ['I])
  7. {
  8. $ Url = "http://tianxiamm.com/viewthread.php? Tid = ". $ tid." & extra = page % 3D2 ";
  9. If (! $ Content = file_get_contents ($ url ))
  10. {
  11. Exit ("script location. href = 'D. php? Id = ". ($ id + 1)." '; script ");
  12. }
  13. Preg_match_all ("| iUs", $ content, $ addr );
  14. If (emptyempty ($ addr [1])
  15. {
  16. Exit ("script location. href = 'D. php? Id = ". ($ id + 1)." '; script ");
  17. }
  18. $ _ SESSION ['addr '] = $ addr [1];
  19. $ _ SESSION ['I'] = 0;
  20. }
  21. For ($ I = $ _ SESSION ['I']; $ I <count ($ _ SESSION ['addr ']); $ I ++)
  22. {
  23. If (! File_exists ($ tid ))
  24. {
  25. Mkdir ($ tid, 0777 );
  26. }
  27. If ($ a = file_get_contents ($ _ SESSION ['addr '] [$ I])
  28. {
  29. $ Fuffix = substr ($ _ SESSION ['addr '] [$ I], strrpos ($ _ SESSION ['addr'] [$ I], '. '), 5 );
  30. $ FileImg = $ tid. '/'. ($ I + 1). $ fuffix;
  31. File_put_contents ($ fileImg, $ a); // write the file
  32. }
  33. $ _ SESSION ['I'] = $ I + 1;
  34. If (time ()-$ t> 18)
  35. {
  36. Exit ("script location. href = 'D. php? Id = ". $ id." '; script ");
  37. }
  38. }
  39. Unset ($ _ SESSION ['addr ']);
  40. Unset ($ _ SESSION ['I]);
  41. Exit ("script location. href = 'D. php? Id = ". ($ id + 1)." '; script ");
  42. ?>

A.txt is a data file
D. php is an image collection program and can be opened and run directly in the browser.



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.