php Code example of download file , Friends in need can refer to
<?php 
$file = 'monkey.gif';  if (file_exists($file)) { 
header('Content-Description: File Transfer'); 
header('Content-Type: application/octet-stream'); 
header('Content-Disposition: attachment; filename='.basename($file)); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
header('Content-Length: ' . filesize($file)); 
ob_clean(); 
flush(); 
readfile($file); 
exit; 

?> 
The above code is the download code .
The online preview pdf File code :
<?php 
/**
*  The online preview pdf file
* edit by www.jbxue.com
*
*/
public function fddAction() 

// get attachment location 
$attachment_location = $_SERVER["DOCUMENT_ROOT"] . "/pdf/fdd/sample.pdf";  if (file_exists($attachment_location)) { 
// attachment exists  // send open pdf dialog to user 
header('Cache-Control: public'); // needed for i.e. 
header('Content-Type: application/pdf'); 
header('Content-Disposition: inline; filename="sample.pdf"'); 
readfile($attachment_location); 
die(); // stop execution of further script because we are only outputting the pdf  } else { 
die('Error: File not found.'); 


?>

Reference link :
http://www.cnblogs.com/yilee/archive/2011/08/16/2140032.html

php Download more articles about the code sample of the file

  1. Batch removal Teleport Pro Download File redundancy code throughout the station

    teleport pro tppabs Batch deletion of labels teleport pro tppabs Batch deletion of labels send use Teleport Pro The downloaded Web page code contains a lot of junk code , For example, downloaded html Page code will ...

  2. [ turn ] Most complete with regular batch removal Teleport Pro Download File redundancy code throughout the station

    Original address :http://www.jb51.net/article/43650.htm html In the original document tppabs Mark is Teleport Pro Marks left by software . The software is an offline browser , After downloading the entire page , it ...

  3. php header Function download file implementation code

    stay php in header The use of functions is very large ,header Not only can you send the original HTTP Headlines , At the same time, you can also download files directly header The most common function is not to download, but to send http Class Jump it ...

  4. Spring mvc Download the file java Code

    /** * Download template file * @author cq */ @RequestMapping("/downloadExcel.do") public ResponseEntity< ...

  5. java Download file function code example

    public static void down(HttpServletRequest request,    HttpServletResponse response) throws Exceptio ...

  6. Ajax Download the file ( No page refresh )

    explain :Ajax File transfer is not possible , This paper just simulates Ajax You can request and return the effect of data without refreshing the page . In essence, it's through submission form Form to return the output of the file stream . Step by step to implement logic : ajax Request server , Access database , according to ...

  7. js send out post Request file download

    Everybody knows ajax You can't download files directly , So it's usually in the form of a hyperlink to download a file But when it comes to the need to send a lot of data to the server and then download, the form of hyperlinks is a little too reluctant Here's a tool approach ( rely on jque ...

  8. Python Extension module ——selenium Use ( location 、 Download files, etc )

    I want to use it comprehensively selenium Can download <selenium 2 Automation test practice - be based on Python Language >PDF Look at your ebook I use a simple browser operation , Download files and other functions ... Recommended firefox ...

  9. asp.net core Download the file , Upload excel file

    Download the file : Code : Back end code : public IActionResult DownloadFile() { var FilePath = @"./files/deparment.xlsx&q ...

Random recommendation

  1. 【 Arrangement 】 To graduate .Net It's a job reserve for farmers

    Statement : The title of this article comes from the Internet , For those who are about to graduate from school .Net Code the agriculture ( Of course , I'm one of them myself ) The use of learning . Of course , After studying these topics, you may not get offer, But it's also good to make targeted preparations for employment . Besides , In addition to technology ...

  2. android Escape characters are commonly used in

    Escape character The actual character name < < Less than no. > > More than no. & & and &apos; ' Single quotation marks " " Double quotes  

  3. UICollectionView The use of small records and some instructions

    // // MallTestViewController.h // fitmiss // // Created by bill on 16/6/28. // Copyright 2016 year lea ...

  4. From input URL What happened to the browser in the process of receiving ?

    From input URL What happened to the browser in the process of receiving ? What really happens when you navigate to a URL The above two articles are well interpreted , Worth reading . Next, let's sum up ...

  5. About tableView Error prompt for

    WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWit ...

  6. [Android UI] shape and selector Combined use of

    shape and selector yes Android UI Often used in design , For example, we need to customize a fillet Button, Click on Button Some of the effects change , You use shape and selector. It can be said that ,shape and ...

  7. (VS) TFS lost mapping suddenly.

    The network at home is not very stable . I suddenly found out today TFS On all the mapping All of a sudden . Try to go remapping, stay Source Control Explorer Right click on the source file , And then choose Advanced ...

  8. ReactNative Environment building

    Reference resources :http://bbs.reactnative.cn/topic/10/%E5%9C%A8windows%E4%B8%8B%E6%90%AD%E5%BB%BAreact-native-androi ...

  9. Spring3.0 Official website document learning notes ( 8、 ... and )--3.4.3~3.4.6

    3.4.3 Use depends-on     Use depends-on Be able to force one or more beans Initialize first , And then we'll talk about this bean To initialize . Multiple bean In between ","." ...

  10. VMware install CentOS Tips : The virtual machine has been configured to use 64 Bit client operating system . however , Unable to execute 64 Bit operation . Solution

    There was an error installing the virtual machine : I checked the information on the Internet , Find out CPU Support VT Technology can support vmware Install in 64 Bit virtual machine . Here are the steps : 1) Download one from the Internet securable.exe, Test whether the following machines support VT. l ...