iOS interface, multi-image batch download, iOS to me is the ID of each picture, but my download can only be performed once, solve (the iOS interface will be used later, is currently debugging on the Web side)?
The code is as follows:
Public Function index () {
$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);
File path
$file_path=$dow_arr['upload_url']; $xinxi = $this->download($file_name,$file_path); }}
Ways to download files
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);}
Reply content:
iOS interface, multi-image batch download, iOS to me is the ID of each picture, but my download can only be performed once, solve (the iOS interface will be used later, is currently debugging on the Web side)?
The code is as follows:
Public Function index () {
$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);
File path
$file_path=$dow_arr['upload_url']; $xinxi = $this->download($file_name,$file_path); }}
Ways to download files
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);}
PHP just need to download the image path to the iOS to go back, before the mistake, because this is the client to download the picture, so only need to return to the path, iOS download operation!!!! (to complicate the question)
If you download it, you can only return one image.
Let iOS, a few pictures, tune the interface several times.
Well, if you have more than one file, you can just loop through the process. Feeling the problem is not very clear.
Do not understand, your this can only download once what is meant,
Or maybe you want this github.com/jeanwolf/httpclient.
This library allows for similar concurrent multi-request processing