symfony1.4 で ajax で画像ファイルのアップロードしたい(javascript側)
http://gokercebeci.com/dev/droparea
を使う。
ちょっと中身書き換えたけど基本的にはテンプレートに
<script type="text/JavaScript"> $(function () { $('.droparea').droparea({ 'instructions': '画像をおいてください', 'over': '画像を離してください', 'start' : function(area){ area.find('.error').remove(); }, 'complete' : function(result, file, input, area){ if (result.error == undefined) { // 正常終了時 if((/image/i).test(file.type)){ area.find('img').remove(); area.append($('<img>',{'src': result.path + result.filename + '?' + Math.random()})); } } else { // エラーがある場合はアラートで出力 alert(result.error); return 0; } } }); }); </script> <input class="droparea spot" type="file" data-post="url" name="file" data-name="top" data-width="200" data-height="150">
みたいな感じでok。