July 14, 2008

Sabel AjaxUploader Sample

Sabel AjaxUploaderのサンプルを用意しました。

こちらで動作の様子を確認できます(100Mまで)。

コードは以下のような感じです。ジェネレータで生成することもできますが、コード量が少ないのでコピペでも楽かと思います。

コントローラ例
<?php

class Index_Controllers_Upload extends Sabel_Controller_Page
{
  public function upload()
  {
    $this->uploadId = md5hash();
  }
  
  public function fetchStatus()
  {
    $status = apc_fetch("upload_" . $this->request->fetchGetValue("uploadId"));
    
    echo json_encode($status);
    exit;
  }
  
  public function uploaded()
  {
    echo "uploaded";
    exit;
  }
}
uploadアクションのテンプレート例(Sabelレンダラ使用)
<script type="text/javascript" src="<?= linkto("js/Sabel.js") ?>"></script>
<script type="text/javascript" src="<?= linkto("js/helpers/AjaxUploader.js") ?>"></script>
<style type="text/css">
@import url("<?= linkto("js/helpers/css/Sabel.css") ?>");
</style>

<div id="progressBar"></div>

<form id="upload_form" enctype="multipart/form-data" action="<?= uri("a: uploaded") ?>" method="post">
  <p>
    <input type="hidden" name="APC_UPLOAD_PROGRESS" value="<?= $uploadId ?>" />
    <input type="file"   name="upfile" /><br />
    <input type="submit" value="upload" />
  </p>
</form>

<script type="text/javascript">
new Sabel.PHP.AjaxUploader("upload_form", "<?= uri("a: fetchStatus") ?>?uploadId=<?= $uploadId ?>", "progressBar");
</script>

  Powered by Sabel

トラックバックURL

コメントする

名前:
URL:
  情報を記憶: 評価:  顔   星
 
 
 
Sabel

Sabel PHP Frameworkを開発しています。
http://www.sabel.jp/

Search
Categories
Tags
Recent Articles
Archives