ちなみに、読んだドキュメントは以下。
- davidpersson / media / Wiki
http://wiki.github.com/davidpersson/media/
- The CakePHP Media Plugin
http://cakephp.org/files/CakeFest/CakeFest%203%20-%20Berlin%202009/Marius%20Wilms%20-%20The%20CakePHP%20Media%20Plugin/The_CakePHP_Media_Plugin.pdf
- Attachments
http://bakery.cakephp.org/articles/view/attachments
ACL は英語圏のドキュメントが多かったので助かったが、
これは現状英語圏でも少ない。
やはり頼みの綱はソース。
config/sql:
media.php
media.sql
models:
attachment.php
models/behaviors:
media.php
polymorphic.php
transfer.php
vendors:
media_validation.php
mime_glob.db
mime_glob.php
mime_magic.db
mime_magic.php
mime_type.php
transfer_validation.php
vendors/medium:
audio.php
css.php
document.php
generic.php
icon.php
image.php
js.php
medium.php
text.php
video.php
vendors/medium/adapter:
basic_image.php
basic_text.php
css_tidy.php
ffmpeg_audio.php
ffmpeg_video.php
gd.php
getid3_audio.php
getid3_video.php
imagick.php
imagick_shell.php
jsmin.php
pear_mp3.php
pear_text.php
vendors/shells:
media.php
vendors/shells/tasks:
collect.php
make.php
sync.php
views/elements:
attachments.ctp
views/helpers:
medium.php
- checkLocation()
//plugins/media/models/attachment.php
var $validate = array(
'file' => array(
...
'location' => array(
'rule' => array(
'checkLocation',
array(MEDIA_TRANSFER, '/tmp/') ..................... (1)
)
)
...
windows に /tmp/ はない。
plugins/media/config/core.php 内で HTTP_TMP として環境に応じて変えればいい。
- checkLocation()
//plugins/media/config/core.php
/**
* MIME type detection by file content
*
* Options:
* engine - `null` for autodetection or `'core'`, `'fileinfo'`,
`'mime_magic'`
* db - Absolute path to a glob db file in freedesktop, apache,
or php format
* (optional for the fileinfo and mime_magic engine,
required for core engine)
*/
Configure::write('Mime.magic', array(
'engine' => null, ........................................ (2)
'db' => null,
));
(2) の設定に応じて
core ......... Media.MimeMagic
fileinfo ..... fileinfo (extension=php_fileinfo.dll)
mime_magic ... mime_content_type (extension=php_mime_magic.dll)
が使われる。
但し、fileinfo は php 5.2.9 で使えるのか?
PHP >= 5.3.0, PECL fileinfo >= 0.1.0
http://www.php.net/manual/ja/function.finfo-open.php
と書いてある。php 5.3.x を使って後で試してみよう。
mime_content_type を使わうと、/tmp/ の一時ファイルが text/plain と解釈されてしまう。
mime_content_type 自体 deprecated なんだから避けるべきかな。
<fieldset>
<legend>Edit B</legend>
<input type="hidden" value="3" name="data[B][id]" />
<div class="attachments element">
Attachments <!-- New Attachment --> .................... (3)
<div class="new">
<input type="hidden" name="data[Attachment][0][model]"
value="B" />
<input type="hidden" name="data[Attachment][0][group]"
value="attachment" />
<div class="input file">
<label for="Attachment0File">File</label>
<input type="file" name="data[Attachment][0][file]" />
</div>
<div class="input text">
<label>Textual replacement</label>
<input type="text" name="data[Attachment][0][alternative]" />
</div>
</div>
<!-- Existing Attachments --> .......................... (4)
<div class="existing">
<div>
<input type="hidden" name="data[Attachment][1][id]" value="3" /
>
<input type="hidden" name="data[Attachment][1][model]"
value="B" />
<input type="hidden" name="data[Attachment][1][group]"
value="attachment" />
<input type="hidden" name="data[Attachment][1][dirname]"
value="transfer/img" />
<input type="hidden" name="data[Attachment][1][basename]"
value="2.png" />
<input type="hidden" name="data[Attachment][1][alternative]" /
>
<img width="16" height="16" alt=""
src="/media_plugin/media/filter/xxs/transfer/img/2.png" /
>
<span>
<a href="/media_plugin/media/transfer/img/2.png">2.png</
a>
(image/2190 Bytes)
<em></em>
</span>
<div class="input checkbox"> ....................... (5)
<input name="data[Attachment][1][delete]" value="0"
type="hidden" />
<input name="data[Attachment][1][delete]" value="1"
type="checkbox" />
<label for="Attachment1Delete">Release</label>
</div>
</div>
</div>
</div>
</fieldset>
(3) ... 追加する場合に使う
(4) ... 関連する既存の attachments が列挙される
(5) ... checkbox により Attachment に delete が付加されて、削除対象となる
- File uploading, file storage and CakePHPs MediaView class
http://cakedc.com/eng/florian_kraemer/2010/01/25/file-uploading-file-storage-and-cakephp-mediaview-class
| ... store your files in a pseudo-random directory structure
| like APP/media/32/a5/3n/
//models/attachment.php
public $actsAs = array(
'Media.Transfer' => array(
'destinationFile' => ':Medium.short::DS::Source.basename:',
ランダムなディレクトリ名を挿入する仕組みは現状の media plugin にはない (ようだ)。
となると、上記ページの _randomPath() の結果を自分で destinationFile に適用する必要がある。
結果、以下のディレクトリに保存され、
webroot/media/transfer/img/34/67/59/1.png
attachments テーブルの dirname フィールドに
transfer/img/34/67/59
が保存されることを確認した。
また、表示する際、xs フィルター適用後の出力として、
/media_plugin/media/filter/xs/transfer/img/34/67/59/1.png
という具合に出力された。
へぇ。
現状の $actsAs の並びからすると、
TransferBehavior.beforeSave() -> MediaBehavior.beforeSave()
の順になっているので、ファイル保存時に checksum は得られない。
# 本当は得られるけど plugin を弄ることになる
但し、その順番は $actsAs の順番だと思うので、それを故意に入れ替えたらどうなるだろう?
入れ替えると、
MediaBehavior.beforeSave() -> TransferBehavior.beforeSave()
となるので、TransferBehavior による一時ファイルの処理が済んでいないので、
その一時ファイルに対する MediaBehavior の処理は失敗する。
// uploadify.as
file.upload(scriptURL, param.fileDataName);
この処理の直前では正しくデータが保持されているのだが、
何故か postData が送られていない。
分からん。
ここで出てきている assocAlias が elements/attachments.ctp で使われるのだが、
$assocAlias を設定するの忘れてしまいそ。
<img width="16" height="16" />
<img width="16" height="16" />
Media Pluginについては、日本の公式コミュニティでも
話題になっていましたよ。
参考にどうぞ。
CakePHP Users in Japan
http://cakephp.jp/modules/newbb/viewtopic.php?viewmode=flat&topic_id=2110&forum=3
http://cakephp.jp/modules/newbb/viewtopic.php?topic_id=2224&forum=3
--
>--
>このメールは Google グループのグループ「CakePHP-ja」の登録者に送られています。
>このグループに投稿するには、cakep...@googlegroups.com にメールを送信してく
>ださい。
>このグループから退会するには、cakephp-ja+...@googlegroups.com にメー
>ルを送信してください。
>詳細については、http://groups.google.com/group/cakephp-ja?hl=ja からこのグ
>ループにアクセスしてください。
はじめまして、nishimura さん。
情報ありがとうございます。
本プラグインの基本的なところは分かってしまったので、別件に移ってしまいました。
でも、本プラグインの今後の進展を眺めていたいと思います。
p.s.
--
2009-02-13 日付の投稿が何処かに溜まっていたみたいです。
ポストしても反映されないなぁ、と思いながら連射したら今頃出てきました。
スパム!
どうやって消そう。
ふぅん。
windows xp sp3
xampp 1.7.1 (php 5.2.9)
flash 10,0,45,2
silverlight 3.0.50106.0
下記サンプルの内、ie8 でまともに動いているのはない。
- All runtimes example
http://www.plupload.com/example_all_runtimes.php
flash, silverlight 両方ともアップロードのパーセンテージが途中で終了する。
実際、アップロードしたファイルは途中で切れている。
動作したのは
gears
html5
のみ。
issues で動いてないぞ、と書かれていたのだが、気にしていなかった。
なんでだ?
ui.dialog のように dom を弄るプラグインでは、element の z-index が変わる。
"Add files" の element と dialog の z-index が逆転していたためにクリックに反応しなかった。
# event handler を調べるため、ソースを片っ端に見てしまった後に気が付くなんて...
また、plupload の google cdn による jquery のバージョンが古過ぎる。
「plupload の」ではなく「google の」cdn が古いんだった。