PHP file download based on database records

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags based connect download file file download php php file php tutorial

PHP Tutorial File download is a database tutorial based on the records and then use the header in PHP to achieve file download.

?
Include './admin/connect.php ';

@extract ($db->get_one ("select * from Movieinfo where id= '. $_get[' id '].");
$db->query ("Update movieinfo set downnum=downnum+1 where id= '". $_get[' id '). "
Control Downloads
$url 2= "./admin/"/The path to the movie


if ($localaddress)
{
$newname = $localaddress;
$movieurl = $url 2 $newname;
}


$type =basename ($movieurl);
$type = substr (STRRCHR ($type, '. '), 0);
$filename = $title. $type;

$file =fopen ($movieurl, ' R ');
Ob_end_clean ();
Header (' Content-type:application/octet-stream ');
Header (' accept-ranges:bytes ');
Header (' Accept-length: ' FileSize ($movieurl));
Header ("content-disposition:attachment; Filename= ". $filename);
Echo fread ($file, FileSize ($movieurl));
Fclose ($file);
Exit;
?>

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.