{"id":10013,"date":"2021-08-18T12:30:39","date_gmt":"2021-08-18T03:30:39","guid":{"rendered":"https:\/\/www.itblog.jp\/?p=10013"},"modified":"2021-08-18T12:30:39","modified_gmt":"2021-08-18T03:30:39","slug":"cakephp3%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%82%b5%e3%83%bc%e3%83%90%e3%81%8b%e3%82%89%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89%e5%be%8c%e3%81%ab%e5%89%8a%e9%99%a4","status":"publish","type":"post","link":"https:\/\/www.itblog.jp\/?p=10013","title":{"rendered":"cakephp3\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u30b5\u30fc\u30d0\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5f8c\u306b\u524a\u9664\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"\n<p>cakephp3\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30b5\u30fc\u30d0\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5f8c\u306b\u524a\u9664\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u306e\u30e1\u30e2\u66f8\u304d\u3067\u3059\u3002<\/p>\n\n\n\n<p>Cakephp3\u3067\u3001\u30b5\u30fc\u30d0\u4e0a\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u306b\u306f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$this->response->withFile(<\/pre>\n\n\n\n<p>\u30e1\u30bd\u30c3\u30c9\u304c\u4fbf\u5229\u3067\u3059\u304c\u3001\u5b9f\u884c\u3057\u305f\u6642\u70b9\u3067\u30d5\u30a1\u30a4\u30eb\u304c\u51fa\u529b\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u305d\u306e\u5f8c\u30b5\u30fc\u30d0\u4e0a\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3057\u3088\u3046\u3068\u3057\u305f\u5834\u5408\u3001\u305d\u306e\u5f8c\u306b\u30d5\u30a1\u30a4\u30eb\u524a\u9664\u3057\u3088\u3046\u3068\u3057\u305f\u5834\u5408\u306b\u3046\u307e\u304f\u884c\u304b\u305a\u306b\u56f0\u3063\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>Laravel\u3060\u3068\u3001<\/p>\n\n\n\n<p>response()->download($pathToFile, $name)->deleteFileAfterSend(true)<\/p>\n\n\n\n<p>\u307f\u305f\u3044\u306a\u65b9\u6cd5\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5f8c\u524a\u9664\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u3001cakephp\u3067\u306f\u306a\u304f\u3001\u3069\u3046\u3057\u305f\u3082\u306e\u304b\u3068\u2026\u3002<\/p>\n\n\n\n<p>\u305d\u308c\u3067\u8272\u3005\u8abf\u3079\u305f\u3068\u3053\u308d\u3001cakephp\u306e\u4e0a\u8a18\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u308f\u305a\u306b\u3001PHP\u306b\u76f4\u63a5\u8a18\u8ff0\u3057\u305f\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5\u3092\u53d6\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>php\u306b\u76f4\u63a5\u66f8\u304f\u5834\u5408\u306f\u3001<\/p>\n\n\n\n<p>\/\/\u30d5\u30a1\u30a4\u30eb\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<br>header (&#8220;Content-disposition: attachment; filename=wa3_db.sql&#8221;);<br>header (&#8220;Content-type: application\/octet-stream; name=wa3_db.sql&#8221;);<\/p>\n\n\n\n<p>\u00a0readfile($fileName);<\/p>\n\n\n\n<p>\u00a0\/\/\u30d5\u30a1\u30a4\u30eb\u524a\u9664<br>\u00a0unlink($fileName);<\/p>\n\n\n\n<p>\u307f\u305f\u3044\u306a\u304b\u3093\u3058\u3067\u3001readfile\u5f8c\u306b\u3001unlink\u3059\u308b\u3053\u3068\u3067\u5bfe\u51e6\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>cakephp3\u3067\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30b5\u30fc\u30d0\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u5f8c\u306b\u524a\u9664\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u306e\u30e1\u30e2\u66f8\u304d\u3067\u3059\u3002 Cakephp3\u3067\u3001\u30b5\u30fc\u30d0\u4e0a\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u306b\u306f $this->response->withFile( \u30e1\u30bd\u30c3\u30c9\u304c\u4fbf\u5229\u3067\u3059 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[165,131],"tags":[],"class_list":["post-10013","post","type-post","status-publish","format-standard","hentry","category-cakephp","category-131"],"_links":{"self":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/10013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10013"}],"version-history":[{"count":0,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=\/wp\/v2\/posts\/10013\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itblog.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}