How to add automatic thumbnails to PHP for image download

Source: Internet
Author: User
In this PHP section, the external link image in titlepic is automatically downloaded. I want it to automatically scale down to a fixed size image during download. How can I modify it? The PHP section {code...} automatically downloads the external link image in titlepic. I want it to automatically scale down to a fixed size image during download. How can I modify it?

$ Sqltext = "SELECT id, titlepic FROM {$ dbtbpre} _ article where titlepic like 'HTTP: // % 'order by id limit 1 "; $ r = $ empire-> fettings ($ sqltext); if ($ r) {$ path = ECMS_PATH. "uploads \ pic \"; $ yname = $ path. basename ($ r [titlepic]); $ filename = '/uploads/pic /'. basename ($ r [titlepic]); if (file_exists ($ yname) & filesize ($ yname)> 0) {echo ($ yname. "already exists
"); // The file exists // exit ('s: '. filesize ($ yname);} else {echo ($ yname ."
Down :". $ r [titlepic]); $ string = ReadFiletext ($ r [titlepic]); WriteFiletext_n ($ yname, $ string); sleep (1 );} $ sqltext = "update {$ dbtbpre} _ article set titlepic = '$ filename' where id =' $ r [id] '"; echo ('
'. $ Sqltext); $ empire-> query ($ sqltext); sleep (1); echo" ";} Else {// echo" "; Echo" completed ";} db_close (); $ empire = null;

Reply content:

In this PHP section, the external link image in titlepic is automatically downloaded. I want it to automatically scale down to a fixed size image during download. How can I modify it?

$ Sqltext = "SELECT id, titlepic FROM {$ dbtbpre} _ article where titlepic like 'HTTP: // % 'order by id limit 1 "; $ r = $ empire-> fettings ($ sqltext); if ($ r) {$ path = ECMS_PATH. "uploads \ pic \"; $ yname = $ path. basename ($ r [titlepic]); $ filename = '/uploads/pic /'. basename ($ r [titlepic]); if (file_exists ($ yname) & filesize ($ yname)> 0) {echo ($ yname. "already exists
"); // The file exists // exit ('s: '. filesize ($ yname);} else {echo ($ yname ."
Down :". $ r [titlepic]); $ string = ReadFiletext ($ r [titlepic]); WriteFiletext_n ($ yname, $ string); sleep (1 );} $ sqltext = "update {$ dbtbpre} _ article set titlepic = '$ filename' where id =' $ r [id] '"; echo ('
'. $ Sqltext); $ empire-> query ($ sqltext); sleep (1); echo" ";} Else {// echo" "; Echo" completed ";} db_close (); $ empire = null;

This is not the western cms. Your need should be to save the remote image and auto scale crop it. Then write a function to add it to WriteFiletext_n. Google can use imagecopyresampled directly or install ImageMagick, which is better than the GD class library.

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.