Ios interface, PHP multi-image batch download how to do?

Source: Internet
Author: User
Ios interface: batch download of multiple images. the ID of each image is sent to me by ios, but the download can only be executed once. (the ios interface will be used later, currently debugging on the web end )? The code is as follows: publicfunctionindex () {code ...} file path {code ...} download... ios interface: batch download of multiple images. the ID of each image is sent to me by ios, but the download can only be executed once. (the ios interface will be used later, currently debugging on the web end )?
The code is as follows:
Public function index (){

$ Download = array (0 => 3, 1 => 5,); foreach ($ download as $ dow_v) {// search for image information in the database $ dow_arr = D ('upload')-> where (array ('up _ id' => $ dow_v)-> find (); // capture the file name $ file_name = substr ($ dow_arr ['upload _ url'], strrpos ($ dow_arr ['upload _ url'], '/') + 1 );

// File path

        $file_path=$dow_arr['upload_url'];        $xinxi = $this->download($file_name,$file_path);    }}

// Method for downloading an object

Public function download ($ file_name = '', $ file_path ='') {// get the size of the downloaded file $ file_size = filesize ($ file_path); // open the file, and determine whether there is $ fp = fopen ($ file_path, "r") or exit ("file does not exist"); // The Returned file http protocol information header ("Content-type: application/octet-stream "); // return the header (" Accept-Ranges: bytes ") by byte size; // return the file size header (" Accept-Length: $ file_size "); // The header (" Content-Disposition: attachment; filename = ". $ file_name); // number of replies sent to the client $ Buffer = 1024; // for download security. We finally make a file byte read counter $ file_count = 0; // judge whether the file ends while (! Feof ($ fp) & ($ file_size-$ file_count> 0) {$ file_data = fread ($ fp, $ buffer ); // count the number of bytes read $ file_count + = $ buffer; // send some data back to the browser echo $ file_data;} fclose ($ fp );}

Reply content:

Ios interface: batch download of multiple images. the ID of each image is sent to me by ios, but the download can only be executed once. (the ios interface will be used later, currently debugging on the web end )?
The code is as follows:
Public function index (){

$ Download = array (0 => 3, 1 => 5,); foreach ($ download as $ dow_v) {// search for image information in the database $ dow_arr = D ('upload')-> where (array ('up _ id' => $ dow_v)-> find (); // capture the file name $ file_name = substr ($ dow_arr ['upload _ url'], strrpos ($ dow_arr ['upload _ url'], '/') + 1 );

// File path

        $file_path=$dow_arr['upload_url'];        $xinxi = $this->download($file_name,$file_path);    }}

// Method for downloading an object

Public function download ($ file_name = '', $ file_path ='') {// get the size of the downloaded file $ file_size = filesize ($ file_path); // open the file, and determine whether there is $ fp = fopen ($ file_path, "r") or exit ("file does not exist"); // The Returned file http protocol information header ("Content-type: application/octet-stream "); // return the header (" Accept-Ranges: bytes ") by byte size; // return the file size header (" Accept-Length: $ file_size "); // The header (" Content-Disposition: attachment; filename = ". $ file_name); // number of replies sent to the client $ Buffer = 1024; // for download security. We finally make a file byte read counter $ file_count = 0; // judge whether the file ends while (! Feof ($ fp) & ($ file_size-$ file_count> 0) {$ file_data = fread ($ fp, $ buffer ); // count the number of bytes read $ file_count + = $ buffer; // send some data back to the browser echo $ file_data;} fclose ($ fp );}

In php, you only need to return the image path to ios. it was wrong because the image is downloaded through the client, so you only need to return the path, download from ios !!!! (Complicate the problem)

Only one image can be returned for download.
For ios, how many images can be called.

Yes. if there are multiple files, just process them cyclically. I feel that the problem is not very clear.
I don't understand. what do you mean by downloading this file only once,
You may also want github.com/JeanWolf/httpclient.
This library can implement concurrent multi-request processing.

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.