ios interface, batch download of multiple pictures, what ios passes to me is the ID of each picture, but my download can only be executed once, please solve (the ios interface will be used later, currently debugging on the web side)?
The code is as follows :
public function index(){
<code>$download =array( 0=>3, 1=>5, ); foreach($download as $dow_v){ //查找数据库中的图片信息 $dow_arr = D('Upload') -> where(array('up_id' => $dow_v)) -> find(); //文件名截取 $file_name = substr($dow_arr['upload_url'], strrpos($dow_arr['upload_url'],'/')+1);</code>
//File path
<code> $file_path=$dow_arr['upload_url']; $xinxi = $this->download($file_name,$file_path); } }</code>
//How to download files
<code> public function download($file_name='',$file_path=''){ //获取下载文件的大小 $file_size=filesize($file_path); // 打开文件,并判断是否存在 $fp = fopen($file_path,"r") or exit("文件不存在"); //返回的文件 http协议信息 header("Content-type:application/octet-stream"); //按照字节大小返回 header("Accept-Ranges:bytes"); //返回文件大小 header("Accept-Length:$file_size"); //这里客户端的弹出对话框 header("Content-Disposition:attachment;filename=".$file_name); //向客户端回送数据 $buffer=1024; //为了下载的安全。我们最后做一个文件字节读取计数器 $file_count=0; //判断文件是否结束 while(!feof($fp)&&($file_size-$file_count>0)){ $file_data=fread($fp,$buffer); //统计读了多少个字节 $file_count+=$buffer; //把部分数据回送给浏览器 echo $file_data; } fclose($fp); }</code>
ios interface, batch download of multiple pictures, what ios passes to me is the ID of each picture, but my download can only be executed once, please solve (the ios interface will be used later, currently debugging on the web side)?
The code is as follows :
public function index(){
<code>$download =array( 0=>3, 1=>5, ); foreach($download as $dow_v){ //查找数据库中的图片信息 $dow_arr = D('Upload') -> where(array('up_id' => $dow_v)) -> find(); //文件名截取 $file_name = substr($dow_arr['upload_url'], strrpos($dow_arr['upload_url'],'/')+1);</code>
//File path
<code> $file_path=$dow_arr['upload_url']; $xinxi = $this->download($file_name,$file_path); } }</code>
//How to download files
<code> public function download($file_name='',$file_path=''){ //获取下载文件的大小 $file_size=filesize($file_path); // 打开文件,并判断是否存在 $fp = fopen($file_path,"r") or exit("文件不存在"); //返回的文件 http协议信息 header("Content-type:application/octet-stream"); //按照字节大小返回 header("Accept-Ranges:bytes"); //返回文件大小 header("Accept-Length:$file_size"); //这里客户端的弹出对话框 header("Content-Disposition:attachment;filename=".$file_name); //向客户端回送数据 $buffer=1024; //为了下载的安全。我们最后做一个文件字节读取计数器 $file_count=0; //判断文件是否结束 while(!feof($fp)&&($file_size-$file_count>0)){ $file_data=fread($fp,$buffer); //统计读了多少个字节 $file_count+=$buffer; //把部分数据回送给浏览器 echo $file_data; } fclose($fp); }</code>
php only needs to return the path of the image to be downloaded to ios. I made a mistake before, because this is downloading the image through the client, so I only need to return the path and download the image on ios! ! ! ! (Complicating the problem)
When downloading, only one picture can be returned.
How many pictures and interfaces can be adjusted for ios?
Well, if there are multiple files, you can just loop through them. I feel like the issue isn't very clear.
I don’t understand, what do you mean you can only download it once?
Maybe what you want is this github.com/JeanWolf/httpclient
This library can achieve similar concurrent multi-request processing