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.