{"id":790,"date":"2025-08-04T16:18:28","date_gmt":"2025-08-04T07:18:28","guid":{"rendered":"https:\/\/nexive.tech\/?p=790"},"modified":"2025-08-04T16:18:28","modified_gmt":"2025-08-04T07:18:28","slug":"%e3%80%90%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%a7%a3%e8%aa%ac%e3%80%91php%e3%81%a7%e3%81%ae%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e5%ad%98%e5%9c%a8%e7%a2%ba%e8%aa%8d%e3%81%a8%e5%ae%89%e5%85%a8","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=790","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011PHP\u3067\u306e\u30d5\u30a1\u30a4\u30eb\u5b58\u5728\u78ba\u8a8d\u3068\u5b89\u5168\u306a\u524a\u9664\u51e6\u7406"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP\u3067\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u5b89\u5168\u306b\u78ba\u8a8d\u3059\u308b\u65b9\u6cd5\u3092\u89e3\u8aac<\/li>\n\n\n\n<li>\u5b9f\u52d9\u3067\u4f7f\u308f\u308c\u308b\u30d5\u30a1\u30a4\u30eb\u524a\u9664\u51e6\u7406\u3068\u305d\u306e\u6ce8\u610f\u70b9\u3092\u7d39\u4ecb<\/li>\n\n\n\n<li>\u524a\u9664\u51e6\u7406\u306b\u304a\u3051\u308b\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3084\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u554f\u984c\u306b\u3082\u89e6\u308c\u308b<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. PHP\u306b\u304a\u3051\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3068\u524a\u9664\u51e6\u7406\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>PHP\u3067\u306f\u3001\u30ed\u30fc\u30ab\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u78ba\u8a8d\u3084\u524a\u9664\u3068\u3044\u3063\u305f\u57fa\u672c\u7684\u306a\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u3092\u6a19\u6e96\u95a2\u6570\u3067\u884c\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<p><code>file_exists()<\/code> \u306f\u6307\u5b9a\u3055\u308c\u305f\u30d1\u30b9\u306b\u30d5\u30a1\u30a4\u30eb\u307e\u305f\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u5b58\u5728\u3059\u308b\u304b\u3092\u78ba\u8a8d\u3067\u304d\u3001<code>unlink()<\/code> \u306f\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b\u95a2\u6570\u3067\u3059\u3002\u3053\u308c\u3089\u306f\u30d5\u30a1\u30a4\u30eb\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u5f8c\u306e\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u51e6\u7406\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u30d5\u30a1\u30a4\u30eb\u306e\u30af\u30ea\u30a2\u3001\u4e0d\u8981\u30ed\u30b0\u306e\u524a\u9664\u306a\u3069\u3001\u65e5\u5e38\u7684\u306a\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u958b\u767a\u3067\u591a\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u7279\u306bWeb\u30a2\u30d7\u30ea\u3067\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u64cd\u4f5c\u3084\u81ea\u52d5\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u3088\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u304c\u4e0d\u78ba\u5b9a\u306a\u5834\u5408\u3082\u591a\u304f\u3001\u5b89\u5168\u306a\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3068\u4f8b\u5916\u3078\u306e\u5bfe\u51e6\u304c\u6c42\u3081\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001\u3053\u308c\u3089\u306e\u95a2\u6570\u306f\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u3084\u30d5\u30a1\u30a4\u30eb\u30ed\u30c3\u30af\u72b6\u614b\u306b\u4f9d\u5b58\u3059\u308b\u305f\u3081\u3001\u8a2d\u8a08\u6642\u306b\u306f\u4e8b\u524d\u6761\u4ef6\u3084\u4f8b\u5916\u767a\u751f\u6642\u306e\u30ed\u30fc\u30eb\u30d0\u30c3\u30af\u306a\u3069\u3082\u8003\u616e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8a73\u7d30\u89e3\u8aac<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u78ba\u8a8d\u3059\u308b: <code>file_exists()<\/code><\/h3>\n\n\n\n<p>\u307e\u305a\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3059\u308b\u304b\u3092\u78ba\u8a8d\u3059\u308b\u57fa\u672c\u7684\u306a\u51e6\u7406\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$file = 'data\/sample.txt';\n\n\/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u78ba\u8a8d\nif (file_exists($file)) {\n    echo \"\u30d5\u30a1\u30a4\u30eb\u306f\u5b58\u5728\u3057\u307e\u3059\\n\";\n} else {\n    echo \"\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\\n\";\n}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$file<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&#39;data\/sample.txt&#39;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u78ba\u8a8d<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #DCDCAA\">file_exists<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$file<\/span><span style=\"color: #D4D4D4\">)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u30d5\u30a1\u30a4\u30eb\u306f\u5b58\u5728\u3057\u307e\u3059<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u307e\u305b\u3093<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u95a2\u6570\u306f\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u3067\u306a\u304f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5b58\u5728\u3082\u78ba\u8a8d\u53ef\u80fd\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u5148\u304c\u5207\u308c\u3066\u3044\u308b\u5834\u5408\u3067\u3082 <code>true<\/code> \u3092\u8fd4\u3059\u70b9\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b: <code>unlink()<\/code><\/h3>\n\n\n\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u78ba\u8a8d\u3057\u305f\u4e0a\u3067\u524a\u9664\u3059\u308b\u5b89\u5168\u306a\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$file = 'data\/sample.txt';\n\nif (file_exists($file)) {\n    if (unlink($file)) {\n        echo \"\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3057\u307e\u3057\u305f\\n\";\n    } else {\n        echo \"\u30d5\u30a1\u30a4\u30eb\u306e\u524a\u9664\u306b\u5931\u6557\u3057\u307e\u3057\u305f\\n\";\n    }\n} else {\n    echo \"\u524a\u9664\u5bfe\u8c61\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\\n\";\n}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$file<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&#39;data\/sample.txt&#39;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #DCDCAA\">file_exists<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$file<\/span><span style=\"color: #D4D4D4\">)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #DCDCAA\">unlink<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$file<\/span><span style=\"color: #D4D4D4\">)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3057\u307e\u3057\u305f<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    } <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u30d5\u30a1\u30a4\u30eb\u306e\u524a\u9664\u306b\u5931\u6557\u3057\u307e\u3057\u305f<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u524a\u9664\u5bfe\u8c61\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u307e\u305b\u3093<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><code>unlink()<\/code> \u306f\u524a\u9664\u306b\u5931\u6557\u3059\u308b\u3068 <code>false<\/code> \u3092\u8fd4\u3059\u305f\u3081\u3001\u660e\u793a\u7684\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u3066\u3044\u3066\u3082\u524a\u9664\u3067\u304d\u306a\u3044\u30b1\u30fc\u30b9<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30b1\u30fc\u30b9\u3067\u306f <code>unlink()<\/code> \u304c\u5931\u6557\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30d5\u30a1\u30a4\u30eb\u304c\u8aad\u307f\u53d6\u308a\u5c02\u7528\u3067\u3001PHP\u5b9f\u884c\u30e6\u30fc\u30b6\u30fc\u306b\u524a\u9664\u6a29\u9650\u304c\u306a\u3044<\/li>\n\n\n\n<li>\u30d5\u30a1\u30a4\u30eb\u304c\u4ed6\u30d7\u30ed\u30bb\u30b9\u306b\u3088\u3063\u3066\u30ed\u30c3\u30af\u3055\u308c\u3066\u3044\u308b<\/li>\n\n\n\n<li>\u30d1\u30b9\u304c\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3060\u3063\u305f\uff08<code>unlink()<\/code> \u306f\u30d5\u30a1\u30a4\u30eb\u5c02\u7528\uff09<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$dir = 'data';\n\n\/\/ \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u5bfe\u3057\u3066unlink\u3059\u308b\u3068\u8b66\u544a\u304c\u767a\u751f\u3059\u308b\nunlink($dir); \/\/ Warning: unlink(data): Is a directory\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$dir<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&#39;data&#39;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u5bfe\u3057\u3066unlink\u3059\u308b\u3068\u8b66\u544a\u304c\u767a\u751f\u3059\u308b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">unlink<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$dir<\/span><span style=\"color: #D4D4D4\">); <\/span><span style=\"color: #6A9955\">\/\/ Warning: unlink(data): Is a directory<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u524a\u9664\u306b\u306f <code>rmdir()<\/code> \u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>is_file()<\/code> \u3068 <code>file_exists()<\/code> \u306e\u4f7f\u3044\u5206\u3051<\/h3>\n\n\n\n<p><code>file_exists()<\/code> \u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3082\u542b\u3081\u3066\u5b58\u5728\u78ba\u8a8d\u3092\u884c\u3044\u307e\u3059\u304c\u3001<code>is_file()<\/code> \u306f\u7d14\u7c8b\u306b\u30d5\u30a1\u30a4\u30eb\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>$path = 'data\/sample.txt';\n\nif (is_file($path)) {\n    echo \"\u3053\u308c\u306f\u30d5\u30a1\u30a4\u30eb\u3067\u3059\\n\";\n} elseif (file_exists($path)) {\n    echo \"\u3053\u308c\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059\\n\";\n} else {\n    echo \"\u5b58\u5728\u3057\u307e\u305b\u3093\\n\";\n}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$path<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&#39;data\/sample.txt&#39;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #DCDCAA\">is_file<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$path<\/span><span style=\"color: #D4D4D4\">)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u3053\u308c\u306f\u30d5\u30a1\u30a4\u30eb\u3067\u3059<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #C586C0\">elseif<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #DCDCAA\">file_exists<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$path<\/span><span style=\"color: #D4D4D4\">)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u3053\u308c\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;\u5b58\u5728\u3057\u307e\u305b\u3093<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u5b9f\u52d9\u3067\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u524d\u306b <code>is_file()<\/code> \u3067\u660e\u793a\u7684\u306b\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u3088\u304f\u3042\u308b\u30df\u30b9\u30fb\u8aa4\u89e3\u30fb\u843d\u3068\u3057\u7a74<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>unlink()<\/code> \u3092\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u5bfe\u3057\u3066\u5b9f\u884c<\/h3>\n\n\n\n<p>\u8aa4\u3063\u3066\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30d1\u30b9\u3092\u6e21\u3059\u3068\u8b66\u544a\u304c\u51fa\u308b\u305f\u3081\u3001\u4e8b\u524d\u306b <code>is_file()<\/code> \u3067\u78ba\u8a8d\u3059\u3079\u304d\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u306e\u898b\u843d\u3068\u3057<\/h3>\n\n\n\n<p><code>unlink()<\/code> \u306f\u5bfe\u8c61\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u3067\u306a\u304f\u3001\u89aa\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u5bfe\u3059\u308b\u66f8\u304d\u8fbc\u307f\u6a29\u9650\u304c\u5fc5\u8981\u3067\u3059\u3002\u7279\u306b\u5171\u6709\u30b5\u30fc\u30d0\u30fc\u74b0\u5883\u3067\u306f\u3053\u306e\u70b9\u3067\u5931\u6557\u3059\u308b\u30b1\u30fc\u30b9\u304c\u591a\u304f\u898b\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u30d5\u30a1\u30a4\u30eb\u304c\u30ed\u30c3\u30af\u3055\u308c\u3066\u3044\u308b<\/h3>\n\n\n\n<p>\u5225\u30d7\u30ed\u30bb\u30b9\u304c\u30d5\u30a1\u30a4\u30eb\u3092\u4f7f\u7528\u4e2d\u306e\u5834\u5408\u3001<code>unlink()<\/code> \u306f\u6c88\u9ed9\u3057\u3066 <code>false<\/code> \u3092\u8fd4\u3059\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u30ed\u30b0\u51fa\u529b\u3084\u660e\u793a\u7684\u306a\u30a8\u30e9\u30fc\u8868\u793a\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP\u3067\u306f <code>file_exists()<\/code> \u3067\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3001<code>unlink()<\/code> \u3067\u30d5\u30a1\u30a4\u30eb\u524a\u9664\u304c\u53ef\u80fd<\/li>\n\n\n\n<li>\u524a\u9664\u524d\u306b\u306f <code>is_file()<\/code> \u3067\u30d5\u30a1\u30a4\u30eb\u7a2e\u5225\u306e\u660e\u793a\u78ba\u8a8d\u304c\u5b89\u5168<\/li>\n\n\n\n<li>\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u3084\u30ed\u30c3\u30af\u72b6\u614b\u306b\u3088\u308b\u524a\u9664\u5931\u6557\u3092\u8003\u616e\u3057\u3001\u4f8b\u5916\u51e6\u7406\u3092\u5165\u308c\u308b\u3053\u3068\u304c\u5b9f\u52d9\u4e0a\u306f\u5fc5\u9808<\/li>\n\n\n\n<li>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u524a\u9664\u306b\u306f <code>rmdir()<\/code> \u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. PHP\u306b\u304a\u3051\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u30c1\u30a7\u30c3\u30af\u3068\u524a\u9664\u51e6\u7406\u3068\u306f\uff1f PHP\u3067\u306f\u3001\u30ed\u30fc\u30ab\u30eb\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u78ba\u8a8d\u3084\u524a\u9664\u3068\u3044\u3063\u305f\u57fa\u672c\u7684\u306a\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u3092\u6a19\u6e96\u95a2\u6570\u3067\u884c\u3048\u307e\u3059\u3002 file_exists() \u306f\u6307\u5b9a\u3055\u308c\u305f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":708,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[85],"tags":[],"class_list":["post-790","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/790","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=790"}],"version-history":[{"count":2,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/790\/revisions"}],"predecessor-version":[{"id":878,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/790\/revisions\/878"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/708"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=790"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}