{"id":4628,"date":"2024-03-01T13:36:20","date_gmt":"2024-03-01T04:36:20","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=4628"},"modified":"2024-03-01T23:39:58","modified_gmt":"2024-03-01T14:39:58","slug":"post-4628","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/4628","title":{"rendered":"\u30e9\u30a4\u30d6\u30e9\u30ea\u7b49\u3092\u4f7f\u7528\u305b\u305a\u30d5\u30a1\u30a4\u30eb\u3092\u30c9\u30e9\u30c3\u30b0&#038;\u30c9\u30ed\u30c3\u30d7\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>form\u306b\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u6a5f\u80fd\u3092\u5b9f\u88c5\u3059\u308b\u5834\u5408\u3001<a href=\"https:\/\/taitan916.info\/blog\/archives\/2329\" target=\"_blank\" rel=\"noopener\">Dropzone.js\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5<\/a>\u3092\u4ee5\u524d\u306b\u30e1\u30e2\u3057\u305f\u3002\u305f\u3060\u305d\u306e\u30e1\u30e2\u306f10\u5e74\u8fd1\u304f\u524d\u306e\u3082\u306e\u306a\u306e\u3067\u3082\u3063\u3068\u826f\u3044\u65b9\u6cd5\u304c\u3042\u308b\u3093\u3058\u3083\u306a\u3044\u304b\u3068\u8abf\u3079\u305f\u3068\u3053\u308d\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u305b\u305a\u5b9f\u88c5\u3067\u304d\u308b\u65b9\u6cd5\u304c\u3042\u3063\u305f\u3002\u4ee5\u4e0b\u306b\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u3084\u308a\u305f\u3044\u3053\u3068<\/h2>\n<p>\u4ee5\u4e0b\u3092\u5b9f\u88c5\u3057\u305f\u3044\u3002<\/p>\n<ul>\n<li>\u30d5\u30a9\u30fc\u30e0\u306binput=\"file\"\u3092\u7528\u610f\u3057\u3001\u305d\u3061\u3089\u3092\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3067\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u3044<\/li>\n<li>\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u30a8\u30ea\u30a2\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u901a\u5e38\u306einput=\"file\"\u3068\u540c\u69d8\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u3044<\/li>\n<li>\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u6642\u306f\u8996\u899a\u7684\u306b\u5206\u304b\u308a\u3084\u3059\u3044\u3088\u3046\u30d7\u30ec\u30d3\u30e5\u30fc\u8868\u793a\u3055\u305b\u305f\u3044<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u6e96\u5099<\/h2>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u51e6\u7406\u306fclass.upload.php\u3092\u4f7f\u3044\u305f\u3044\u306e\u3067<a href=\"https:\/\/taitan916.info\/blog\/archives\/4611#i-2\" target=\"_blank\" rel=\"noopener\">\u904e\u53bb\u8a18\u4e8b<\/a>\u3092\u53c2\u7167\u306e\u4e0a\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304a\u304f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<h3>\u30d5\u30a9\u30fc\u30e0\u5074(index.php)<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;html lang=\"ja\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"utf-8\"&gt;\r\n&lt;\/head&gt;\r\n&lt;style&gt;\r\n#drop_zone {\r\n    border: 5px solid blue;\r\n    width: 200px;\r\n    height: 100px;\r\n}\r\n#drop_zone input {\r\n    display: block;\r\n    opacity: 0;\r\n}\r\n&lt;\/style&gt;\r\n&lt;body&gt;\r\n    &lt;form action=\"upload.php\" method=\"post\" enctype=\"multipart\/form-data\"&gt;\r\n        &lt;div id=\"preview\"&gt;&lt;\/div&gt;\r\n        &lt;div id=\"drop_zone\"&gt;\r\n            \u30d5\u30a1\u30a4\u30eb\u3092\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3067\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044\u3002\r\n            &lt;input type=\"file\" name=\"file\" id=\"file\"&gt;\r\n        &lt;\/div&gt;\r\n        &lt;input type=\"submit\" name=\"submit\" value=\"\u9001\u4fe1\"&gt;\r\n    &lt;\/form&gt;\r\n    &lt;script type=\"text\/javascript\" src=\"https:\/\/code.jquery.com\/jquery-3.7.1.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;script&gt;\r\n    $(function(){\r\n        $(`#file`).on('change', function(){\r\n\r\n            \/\/\u753b\u50cf\u53d6\u5f97\r\n            const file = $(this).prop('files')[0];\r\n            const type = file.type;\r\n\r\n            \/\/\u753b\u50cf\u304b\u3069\u3046\u304b\u30c1\u30a7\u30c3\u30af\r\n            if( !type.match(\/^image\/) ){\r\n                alert('\u753b\u50cf\u3092\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044');\r\n                $(this).val('');\r\n                return false;\r\n            }\r\n\r\n            \/\/FileReader\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\r\n            let reader = new FileReader();\r\n\r\n            \/\/\u753b\u50cf\u306e\u8aad\u307f\u8fbc\u307f\r\n            reader.readAsDataURL(file);\r\n\r\n            \/\/\u8aad\u307f\u8fbc\u307f\u5931\u6557\u6642\r\n            reader.onerror = function(){\r\n                alert('\u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u53d6\u308a\u306b\u5931\u6557\u3057\u307e\u3057\u305f');\r\n                $(this).val('');\r\n                return false;\r\n            }\r\n\r\n            \/\/\u753b\u50cf\u3092\u8868\u793a\r\n            reader.onload = function() {\r\n                $(`#preview`).html(`&lt;img src=\"${reader.result}\" style=\"width:100px;\"&gt;`)\r\n            }\r\n        });\r\n    });\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h3>\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u5074(upload.php)<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php\r\nrequire_once 'class.upload.php';\r\n\r\n$file = $_FILES['file'];\r\n$lang = 'ja_JP';\r\n\r\n$handle = new \\Verot\\Upload\\Upload($file, $lang);\r\n\r\nif( $handle-&gt;uploaded ){\r\n\r\n    \/\/\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u5909\u66f4\r\n    $handle-&gt;file_new_name_body = date('YmdHis');\r\n\r\n    \/\/\u540c\u4e00\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u5834\u5408\u306f\u4e0a\u66f8\u304d\r\n    $handle-&gt;file_overwrite = true;\r\n\r\n    \/\/\u30a2\u30b9\u30da\u30af\u30c8\u6bd4\u306f\u305d\u306e\u307e\u307e\u3067\u6a2a\u5e45\u3092300px\u306b\u30ea\u30b5\u30a4\u30ba\r\n    $handle-&gt;image_resize = true;\r\n    $handle-&gt;image_x = 300;\r\n    $handle-&gt;image_ratio = true;\r\n\r\n    $handle-&gt;image_convert = 'webp';\r\n\r\n    \/\/\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u6307\u5b9a\r\n    $handle-&gt;process('.\/file\/');\r\n    if( $handle-&gt;processed ){\r\n        \/\/\u6210\u529f\u51e6\u7406\r\n        echo 'success';\r\n\r\n    }else{\r\n        \/\/\u30a8\u30e9\u30fc\u51e6\u7406\r\n        echo $handle-&gt;error;\r\n    }\r\n\r\n}else{\r\n    \/\/\u30a8\u30e9\u30fc\u51e6\u7406\r\n    echo $handle-&gt;error;\r\n}<\/pre>\n<h3>\u89e3\u8aac<\/h3>\n<p>\u521d\u3081\u3066\u77e5\u3063\u305f\u3093\u3060\u3051\u3069input=\"file\"\u81ea\u4f53\u304c\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u53ef\u80fd\u307f\u305f\u3044\u3002\u305d\u306e\u305f\u3081\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3082\u3057\u304f\u306f\u901a\u5e38\u306e\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u5f8c\u300c$(`#file`).on('change', function(){\u300d\u306b\u3066\u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u8868\u793a\u3059\u308b\u3068\u3044\u3046\u5f62\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u30b5\u30e0\u30cd\u30a4\u30eb\u8868\u793a\u306b\u95a2\u3057\u3066\u8a73\u3057\u304f\u306f<a href=\"https:\/\/taitan916.info\/blog\/archives\/3412\" target=\"_blank\" rel=\"noopener\">\u904e\u53bb\u8a18\u4e8b<\/a>\u53c2\u7167\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p>\u4eca\u56de\u306e\u65b9\u6cd5\u4ee5\u5916\u306b\u3082<a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/API\/HTML_Drag_and_Drop_API\" target=\"_blank\" rel=\"noopener\">HTML Drag and Drop API<\/a>\u3068\u3044\u3046HTML\u306eWeb API\u304c\u3042\u308b\u3089\u3057\u3044\u306e\u3067\u5f8c\u65e5\u8a66\u3057\u3066\u307f\u305f\u3044\u3068\u3053\u308d\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u53c2\u8003\u30b5\u30a4\u30c8<\/h2>\n<p><a href=\"https:\/\/blog.kimizuka.org\/entry\/2020\/08\/11\/080000\">https:\/\/blog.kimizuka.org\/entry\/2020\/08\/11\/080000<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>form\u306b\u30c9\u30e9\u30c3\u30b0&amp;\u30c9\u30ed\u30c3\u30d7\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u6a5f\u80fd\u3092\u5b9f\u88c5\u3059\u308b\u5834 ... <\/p>\n","protected":false},"author":1,"featured_media":1071,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3,4],"tags":[91],"class_list":["post-4628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery","category-javascript","tag-image"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=4628"}],"version-history":[{"count":3,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4628\/revisions"}],"predecessor-version":[{"id":4631,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4628\/revisions\/4631"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1071"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=4628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=4628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=4628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}