﻿{"id":1072,"date":"2016-02-04T16:38:23","date_gmt":"2016-02-05T00:38:23","guid":{"rendered":"http:\/\/www.anvilsoftcraft.com\/weblog\/?p=1072"},"modified":"2016-02-05T08:50:33","modified_gmt":"2016-02-05T16:50:33","slug":"%e3%83%95%e3%82%a9%e3%83%bc%e3%83%a0%e3%82%92%e4%bd%bf%e3%82%8f%e3%81%9a%e3%80%81%e7%94%bb%e9%9d%a2%e9%81%b7%e7%a7%bb%e3%82%82%e3%81%9b%e3%81%9a%e3%81%ab%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92","status":"publish","type":"post","link":"https:\/\/www.anvilsoftcraft.com\/weblog\/?p=1072","title":{"rendered":"\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u308f\u305a\u3001\u753b\u9762\u9077\u79fb\u3082\u305b\u305a\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9"},"content":{"rendered":"<p>\u4e45\u3005\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u30cd\u30bf\u3002HTML\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u308f\u305a\u3001\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u306e\u30a2\u30a4\u30c6\u30e0\u3060\u3051\u3092\u4f7f\u3063\u3066\u753b\u9762\u9077\u79fb\u3057\u306a\u3044\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5\u3002<br \/>\n\u52d5\u4f5c\u6761\u4ef6\u3068\u3057\u3066\u3001FormData\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u4f7f\u3048\u308b\u30d6\u30e9\u30a6\u30b6\uff08Chrome7\u3001FF4\u3001Safari5\u3001IE10\u4ee5\u964d\u306a\u3069\uff09\u3058\u3083\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3002(\u52d5\u4f5c\u672a\u78ba\u8a8d\u3002\u3002\u3002\uff09<\/p>\n<p>\u30fbHTML\u5074\u306b\u4e57\u305b\u308b\u30b3\u30fc\u30c9\u3002<br \/>\n1.\u3000\u30da\u30fc\u30b8\u306e\u3069\u3053\u304b\u306b\u4e0b\u8a18\u30b3\u30fc\u30c9(\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u30d5\u30a9\u30fc\u30e0\u30a2\u30a4\u30c6\u30e0)\u3092\u5165\u308c\u308b\u3002FORM\u30bf\u30b0\u306f\u306a\u304f\u3066\u3082\u3044\u3044\u3002<\/p>\n<pre class=\"lang:default decode:true \" >&lt;input type=\"file\" name=\"uploadfile\" id=\"upload\" \/&gt;<\/pre>\n<p>2.\u3000JavaScript\u90e8\u5206\uff08\u30d8\u30c3\u30c0\u306b\u8a18\u8ff0\uff09\u3000\u4e0a\u8a18ID=&#8221;upload&#8221;\u3000\u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u3089\u547c\u3070\u308c\u308b\u3002\u3053\u3053\u3067\u306fJQuery\u4f7f\u7528\u3002<\/p>\n<pre class=\"lang:default decode:true \" >$(function(){\r\n    $('#upload').on(\"change\", function(){\r\n        if (window.FormData){             \/\/\u3000FormData\u306b\u30d6\u30e9\u30a6\u30b6\u304c\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\r\n            var fileObj = $('#upload')[0].files[0];    \/\/ \u30d5\u30a1\u30a4\u30eb\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u53d6\u308a\u51fa\u3057\r\n            if ( fileObj != null ){\r\n                fileupload(fileObj);\r\n            }\r\n        }else{\r\n            alert(\"\u3053\u306e\u30d6\u30e9\u30a6\u30b6\u306fFormData\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u305b\u3093\u3002\");\r\n            return null;\r\n        }\r\n    });\r\n});\r\n<\/pre>\n<p>3.\u3000\u4e0a\u304b\u3089\u547c\u3070\u308c\u308bfileupload()\u95a2\u6570<\/p>\n<pre class=\"lang:default decode:true \" >function fileupload(fileObj){\r\n    var fd = new FormData();            \/\/\u3000FormData\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u751f\u6210\r\n    fd.append('uploadfile', fileObj);    \/\/\u30d5\u30a9\u30fc\u30e0\u30a2\u30a4\u30c6\u30e0\u540d\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092fd\u306b\u8ffd\u52a0\r\n    $.ajax({\r\n        url: 'fileupload.php',    \/\/\u3000\u30d5\u30a1\u30a4\u30eb\u3092\u6e21\u3059PHP\u30d5\u30a1\u30a4\u30eb\r\n        type: 'POST',\r\n        processData : false,    \/\/\u3000\u91cd\u8981\uff01\u3053\u308c\u304c\u306a\u3044\u3068\u52d5\u4f5c\u3057\u306a\u3044\r\n        contentType : false,    \/\/\u3000\u91cd\u8981\uff01\u3053\u308c\u304c\u306a\u3044\u3068\u52d5\u4f5c\u3057\u306a\u3044\r\n        dataType : \"text\",\r\n        data: fd\r\n    })\r\n    .done( function(text){\r\n        console.log(text);\r\n    });\r\n}<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u3067\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3000processData\u3001contentType\u3092false\u306b\u3057\u306a\u3044\u3068JQuery\u304c\u6574\u5f62\u3057\u3066\u3057\u307e\u3046\u306e\u3067\u5fc5\u305a\u3053\u308c\u3089\u306bfalse\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3053\u3068\u3002<\/p>\n<p>\u30fb\u547c\u3070\u308c\u308bPHP\u306e\u30b3\u30fc\u30c9(fileupload.php)<\/p>\n<pre class=\"lang:default decode:true \" >$sSavePath = UPLOAD_FOLDER; \/\/\u30d5\u30a1\u30a4\u30eb\u4fdd\u5b58\u5148\u306e\u30d1\u30b9\r\n$config = array();\r\n$config['upload_path'] = $sSavePath;\r\n$config['max_size'] = MAX_UPLOAD_SIZE;        \/\/ Max upload filesize 300(kb)\r\n$config['max_width'] = MAX_IMAGE_PIXELS;      \/\/ Max Image width 1280px\r\n$config['max_height'] = MAX_IMAGE_PIXELS;     \/\/ Max Image height 1280px\r\n$config['overwrite'] = TRUE;        \/\/ File Overwrite enable\r\n$config['allowed_types'] = \"gif|png|jpg\";\r\n$config['file_name'] = $_FILES['uploadfile']['name'];\r\n$this-&amp;gt;load-&amp;gt;library('upload', $config);\r\n\r\nif ( !$this-&amp;gt;upload-&amp;gt;do_upload('uploadfile') ){\r\n    echo \"Upload Failed.\";\r\n    return FALSE;\r\n} else {\r\n    echo \"Upload Success.\";\r\n}<\/pre>\n<p>\u203b\u3000\u3053\u3053\u3067\u306fCodeIgniter\u4f7f\u7528\u3002\u3082\u3061\u308d\u3093\u666e\u901a\u306bPHP\u306e\u307f\u3067\u3082Ok.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e45\u3005\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u30cd\u30bf\u3002HTML\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u4f7f\u308f\u305a\u3001\u30d5\u30a1\u30a4\u30eb\u9078\u629e\u306e\u30a2\u30a4\u30c6\u30e0\u3060\u3051\u3092\u4f7f\u3063\u3066\u753b\u9762\u9077\u79fb\u3057\u306a\u3044\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5\u3002 \u52d5\u4f5c\u6761\u4ef6\u3068\u3057\u3066\u3001FormData\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u4f7f\u3048\u308b\u30d6\u30e9\u30a6\u30b6\uff08Chrome7\u3001FF4 &hellip; <a href=\"https:\/\/www.anvilsoftcraft.com\/weblog\/?p=1072\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-1072","post","type-post","status-publish","format-standard","hentry","category-software-development","category-6"],"_links":{"self":[{"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/1072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1072"}],"version-history":[{"count":0,"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/1072\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anvilsoftcraft.com\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}