PHP file download code _ php Tutorial-PHP Tutorial

Source: Internet
Author: User
Php file download code. $ F_idisset ($ _ GET [id])? $ _ GET [id]:; $ t_idisset ($ _ GET [tid])? $ _ GET [tid]:; $ t_na ($ t_su_photo;} elseif ($ t_id2) {$ t_na $ f_id = isset ($ _ GET ['id'])? $ _ GET ['id']: '';
$ T_id = isset ($ _ GET ['tid'])? $ _ GET ['tid']: '';
$ T_na = ($ t_id = 1 )? "Su_photo": "su_video ";
If ($ t_id = 1 ){
$ T_na = 'Su _ photo ';
} Else if ($ t_id = 2 ){
$ T_na = 'Su _ video ';
} Else {
$ T_na = 'Su _ cert ';
}
$ SQL = "select * from $ t_na where id = $ f_id and uid = '". $ _ SESSION ['xm']. "'";
$ Result = mysql_query ($ SQL) or exit ("system busy ...");
If (! Mysql_num_rows ($ result) {exit ("
Alert ('record does not exist! '); History. back ();
");}
$ Rs = mysql_fetch_object ($ result );
$ File_name = substr ($ rs-> path, strrpos ($ rs-> path, "/") + 1 );
$ File_dir = substr ($ rs-> path, 0, strlen ($ rs-> path)-strlen ($ file_name ));
$ File_dir = realpath (str_replace ('../', '', $ file_dir ))."\";
$ Rpath = $ file_dir. $ file_name;
If (! File_exists ($ rpath) {// check whether the file exists
Exit ("
Alert ('file not found! '); History. back ();
");
} Else {
$ Tent = substr ($ rpath, strrpos ($ rpath, ".") + 1 );
$ File = fopen ($ rpath, "r"); // open the file
Header ("Content-type:". headertype ($ tent )."");
Header ("Accept-Ranges: bytes ");
Header ("Accept-Length:". filesize ($ file_dir. $ file_name ));
Header ("Content-Disposition: attachment; filename =". $ file_name );
Echo fread ($ file, filesize ($ file_dir. $ file_name ));
Fclose ($ file );
Exit ("
Alert ('Download complete! '); History. back ();
");
}
Function headertype ($ type ){
Switch ($ type ){
Case 'GIF ':
Return 'image/GIF ';
Break;
Case 'jpg ':
Return 'image/pjpeg ';
Break;
Case 'bmp ':
Return 'image/bmp ';
Break;
Case 'PNG ':
Return 'image/x-png ';
Break;
Case 'txt ':
Return 'application/octet-stream ';
Break;
Case 'Zip ':
Return 'application/x-zip-compressed ';
Break;
Case 'rar ':
Return 'application/x-rar-compressed ';
Break;
Case 'Doc ':
Return 'application/msword ';
Break;
Case 'swf ':
Return 'application/x-shockwave-Flash ';
Break;
Case 'wma ':
Return 'audio/x-ms-wma ';
Break;
Case 'rm ':
Return "application/vnd. rn-realmedia ";
Break;
Case 'mp3 ':
Return "audio/mp3 ";
Break;
Default:
Return 'text/plain ';
}
}
?>


Vertex = isset ($ _ GET ['id'])? $ _ GET ['id']: ''; $ t_id = isset ($ _ GET ['tid'])? $ _ GET ['tid']: ''; $ t_na = ($ t_id = 1 )? Su_photo: su_video; if ($ t_id = 1) {$ t_na = 'Su _ photo ';} else if ($ t_id = 2) {$ t_na...

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.