PHP Download problem error Do not know why?

Source: Internet
Author: User
Keywords Php
Tags php download
Php

$file _name = "shunping. jpg";
$file _name=iconv ("GB2312", "GBK", $file _name);//error .... Can you help me change it?
if (!file_exists ($file _name))
{
echo "file does not exist";
return;
}
$fp = fopen ($file _name, "R");
$file _size = filesize ($file _name);
$fp = fopen ($file _name, "R");
Get the size of the download file
$file _size = filesize ($file _name);
The returned file
Header ("Content-type:application/octet-stream");
Returns by byte size
Header ("Accept-ranges:bytes");
Return file size
Header ("Accept-length: $file _size");
Here the client's popup dialog box, corresponding to the file name
Header ("content-disposition:attachment; Filename= ". $file _name);
Loopback data to the client
$buffer = 1024;
In order to download security, we'd better make a file byte read counter
$file _count = 0;
This sentence is used to determine whether the file ends
while (!feof ($fp) && ($file _size-$file _count>0))
{
$file _data = fread ($fp, $buffer);

    //统计读了多少个字节    $file_count+=$buffer;    //把部分数据回送给浏览器    echo $file_data;}    fclose($fp);

?>

  • 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.