PHP code to achieve file downloads, read PHP code to achieve file downloads, we generally implement download is to call the URL to download, but encountered IE can identify open files can not be used in this way, such as downloading a picture, HTML page, etc., then need to program to achieve, The following PHP code can resolve:? if (empty $_get[our general implementation downloads are called URLs to download, but encountered IE can identify open files can not be used in this way, such as downloading a picture, HTML page, etc., then need to program to achieve, The following PHP code can be resolved:
Copy Code code as follows:
.
if (Empty ($_get[' FileName ') | | | empty ($_get[' Filedir ')) | | empty ($_get[' Fileid ']) {
echo ' <script> alert ("Illegal connection!"); Location.replace ("index.php") </script> '; Exit ();
}
$file _name=$_get[' FileName '];
$file _dir=$_get[' Filedir '];
$FileId =$_get[' Fileid '];
$file _dir = $file _dir. " /";
if (!file_exists ($file _dir. $file _name)) {//Check for file presence
echo "File not found";
Exit;
} else {
$file = fopen ($file _dir. $file _name, "R");//Open file
//input file label
Header ("Content-type:applicat Ion/octet-stream ");
Header ("accept-ranges:bytes");
Header ("Accept-length:". FileSize ($file _dir. $file _name));
Header ("content-disposition:attachment; Filename= ". $file _name);
//Output file Contents
Echo fread ($file, FileSize ($file _dir. $file _name));
Fclose ($file);
exit ();
}
?>