{"id":838,"date":"2012-06-29T21:03:17","date_gmt":"2012-06-29T13:03:17","guid":{"rendered":"http:\/\/www.poloo.org\/?p=838"},"modified":"2012-06-29T21:04:18","modified_gmt":"2012-06-29T13:04:18","slug":"%e9%80%9a%e8%bf%87php%e4%b8%8b%e8%bd%bd%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=838","title":{"rendered":"\u901a\u8fc7PHP\u4e0b\u8f7d\u6587\u4ef6"},"content":{"rendered":"<p>php \u4e0b\u8f7d\u6587\u4ef6\u793a\u4f8b\uff1a<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n$file = 'monkey.gif';\r\n\r\nif (file_exists($file)) {\r\n    header('Content-Description: File Transfer');\r\n    header('Content-Type: application\/octet-stream');\r\n    header('Content-Disposition: attachment; filename='.basename($file));\r\n    header('Content-Transfer-Encoding: binary');\r\n    header('Expires: 0');\r\n    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');\r\n    header('Pragma: public');\r\n    header('Content-Length: ' . filesize($file));\r\n    ob_clean();\r\n    flush();\r\n    readfile($file);\r\n    exit;\r\n}\r\n?&gt;<\/pre>\n<p><!--more--><br \/>\nPS\uff1aPDF\u9884\u89c8\u4ee3\u7801\uff1a<\/p>\n<pre class=\"brush:php\">\r\n&lt;?php\r\n    public function fddAction()\r\n    {\r\n        \/\/ get attachment location\r\n        $attachment_location = $_SERVER[\"DOCUMENT_ROOT\"] . \"\/pdf\/fdd\/sample.pdf\";\r\n         \r\n        if (file_exists($attachment_location)) {\r\n            \/\/ attachment exists\r\n             \r\n            \/\/ send open pdf dialog to user\r\n            header('Cache-Control: public'); \/\/ needed for i.e.\r\n            header('Content-Type: application\/pdf');\r\n            header('Content-Disposition: inline; filename=\"sample.pdf\"');\r\n            readfile($attachment_location);\r\n            die(); \/\/ stop execution of further script because we are only outputting the pdf\r\n             \r\n        } else {\r\n            die('Error: File not found.');\r\n        }\r\n    }\r\n?&gt;\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>php \u4e0b\u8f7d\u6587\u4ef6\u793a\u4f8b\uff1a &lt;?php $file = &#8216;monk&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[36,86,63,43,111],"class_list":["post-838","post","type-post","status-publish","format-standard","hentry","category-Php","tag-php-2","tag-86","tag-63","tag-43","tag-111"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=838"}],"version-history":[{"count":2,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/838\/revisions"}],"predecessor-version":[{"id":840,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/838\/revisions\/840"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}