OZの部屋

なんでも日記です

prototype.js + ruby + rmagick で画像アップロード No1

2011-03-09 15:58:03 | プログラム
久しぶりにポスト

画像アップロードライブラリをあちこち探してみましたが、
うまく動かなかったり、で、自分でゼロから作ることにした。

プログレスバー付き、
サムネイルを保存、
最大サイズを決めてアップロードした画像が大きければリサイズする。

IE6,IE8,Firefoxで確認 safari が動かない???

PHPならすぐ出来るみたいだけれど、
Ajax でファイルアップロードを実現するためにかなり時間がかかってしまったが、そこそこに出来たと思う。
細かいところ、まだバグはあるかもしれないが、なかなかかっこいい。

 

HTMLで必要なライブラリは prototype.js
ruby 必要なライブラリは 
        json
    Rmagick(これ結構インストールではまることある jpeg,gif,png 対応必要)

サンプルHTML      ozUploadTest.htm   このページ
スタイルシート    ozUpload.css       このページ
Javascriptソース ozUpload.js        次
Rubyソース        upload.cgi         次の次
プログレスバー用GIF    <--- ozUpload.cssの.progressbardivのbackground-image:url(/images/barbar.gif);を保存したディレクトリに調整のこと

サンプルHTMLソース ozUploadTest.htm
-----------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--
画像アップロード 使い方
javascriptライブラリ prototype.js 1.6以上
日本語円コーディングは UTF8

最も単純な使い方は
HTML body 内に<div id='uploadarea'></div>を記入
head内スクリプトで次の1行
ozUpload('上のフォームエレメントID','サーバー受け側CGIのURL');
-->

<link href="ozUpload.css" rel="stylesheet" type="text/css">
<script src="xxxxxx/prototype.js" type="text/javascript"></script> <!--- ディレクトリ調整必要 -->
<script src="xxxxxx/ozUpload2.js" type="text/javascript"></script> <!--- ディレクトリ調整必要 -->
<script>
function uploadfunc(json)
{
    //ozUpload.js内のfunction ozpostedupload(json) を参考に処理を行う
    $(json.outputid1).style.visibility='visible';
    if(!json.stat){
        $(json.outputid1).innerHTML=json.message;
    }else{
        $(json.outputid1).innerHTML=
        "<a>"+
        "<img>"+
        "</a>";
        $(json.outputid2).innerHTML='これは独自ハンドラです'+json.uploadid +''+
        (json.shrink?"大きいため縮小されました":"");
    }
}
function afterfunc1(json)
{
    $(json.outputid2).innerHTML='After Func 実行'+json.thumbpath;
}
var cgiurl='/cgi-bin/upload.cgi';
//最も単純な呼び出し
ozUpload('uploadarea',cgiurl);
//アップロード完了後独自Function実行
ozUpload('uploadarea3',cgiurl,{postfunc:uploadfunc});
//いろいろなパラメータ設定
ozUpload(
    'uploadarea2',
    cgiurl,
    {
        max_file_size:200,
//        postfunc:uploadfunc,
        afterfunc:afterfunc1,
        img_format:'jpeg,gif',
        no_output2:true,
        output2_html:"<div>aaaacccc<h2>xxx</h2></div>"
    }
);

</script>
<style>
.uploadarea{
    width:600px;
    height:160px;
}
</style>
</head>
<body>
 <form name='f1'>
  <table>
   <tr><th>no1</th><th>no2</th><th>no3---</th></tr>
   <tr><td>aaaaa</td><td>bbbbbbb</td><td>cccccccdddddcc</td></tr>
   <tr><td>1111</td><td>2222</td><td>333</td></tr>
   <tr><td> <div>&nbsp;</div></td></tr>
   <tr><td> <div>&nbsp;</div></td></tr>
   <tr><td> <div>&nbsp;</div></td></tr>
  </table>
 </form>
</body>
</html>


------------------- ozUpload.css おわり --------------------

文字数が多くなるので
Javascriptソース ozUpload.js と
Rubyソース upload.cgi はそれぞれ別にアップ





最新の画像もっと見る

2 コメント

コメント日が  古い順  |   新しい順
hervelegerdress@outlook.com (herve leger dresses)
2020-02-24 23:24:32
http://blog.udn.com/legerdresses/131611285
http://blog.udn.com/legerdresses/131611306
https://is.gd/UqXosW
https://is.gd/Oxatfs
http://bit.ly/2RBc1y1
http://bit.ly/2RDznTD
http://bit.ly/2RC8dfL
https://legerdresses.cocolog-nifty.com/blog/2020/01/post-742927.html
http://bit.ly/2uGk3fV
https://tinyurl.com/v3rrmbl
https://tinyurl.com/rbw7wfz
https://tinyurl.com/r2nab32
https://legerdresses.cocolog-nifty.com/blog/2020/01/post-ec4292.html
https://tinyurl.com/uoyl39m
http://bit.ly/2TckPKr
http://bit.ly/2T1o1Z0
https://tinyurl.com/wxfa4sl
http://bit.do/fqVZX
http://bit.do/fqV2k
http://bit.do/fqV2Y
https://legerdresses.cocolog-nifty.com/blog/2020/01/post-9a248b.html
https://telegra.ph/HERVE-LEGER-STORY-01-28
https://telegra.ph/HERVE-LEGER-HISTORY-01-28
https://is.gd/1Jg3ua
https://is.gd/T42sNN
https://is.gd/lzxx6Z
https://is.gd/TSgxmD
https://is.gd/QghDQ6
http://bit.ly/2GApyzz
http://bit.ly/2GApC2h
http://bit.ly/2vzd2hD
https://tinyurl.com/s7j3mzd
https://tinyurl.com/rpko8mg
http://bit.do/fqV27
http://bit.do/fqV3T
http://bit.do/fqV4c
返信する
Imitazione Rolex (Imitazione Rolex)
2021-11-29 15:40:44
https://weheartit.com/orologimeccanici
https://is.gd/q9491M
https://is.gd/GhSJT3
https://is.gd/NNBBXq
https://is.gd/lomyNL
https://is.gd/JZ8gLQ
https://is.gd/Jxa6UU
https://downtownhoustontx.bubblelife.com/users/orologimeccanici
https://bit.ly/3oEI4w8
https://bit.ly/3kMqaqb
https://bit.ly/3oytNkQ
https://bit.ly/3wRDYEG
https://bit.ly/3kKyDu2
https://bit.ly/30ulXAn
https://downtownhoustontx.bubblelife.com/community/orologimeccanici
https://tinyurl.com/53dke2mf
https://tinyurl.com/3dvhvk34
https://tinyurl.com/bjcu55xx
https://tinyurl.com/43ejhvkc
https://tinyurl.com/mzxr2vx3
https://tinyurl.com/xus4pjwp
https://downtownhoustontx.bubblelife.com/community/orologimeccanici/library/353762764/key/3511437013/QUAL_E_IL_ROLEX_MENO_COSTOSO
https://rapichat.com/orologimeccanici
http://tiny.cc/51qluz
http://tiny.cc/61qluz
http://tiny.cc/71qluz
http://tiny.cc/81qluz
http://tiny.cc/91qluz
http://tiny.cc/a1qluz
https://flipboard.com/@orologiwatch/replica-watches-981busgtz/repliche-orologi-orologi-replica-di-marca-online-imitazione-orologi-italia-rep/a-MjExoXu5QAiT-5vHk9EJKA%3Aa%3A3795843747-bb0bec152f%2Freplichediorologi.eu
https://rebrand.ly/vj5z52l
https://rebrand.ly/vcnfe83
https://rebrand.ly/eot2roz
https://rebrand.ly/o3gfedm
返信する