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

Source: Internet
Author: User
Tags fread ranges
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

  • Related Article

    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.