- 2008年10月 2日 14:54
http://www.reversefolds.com/articles/show/filehandler
基本は、↑のページのものを使うのですが、
1.2でのフォームヘルパとかちょっと変わってるので、
そのままでは1.2では動きませんでした。
ので、ちょっと変更したやつをおいておきます。
rf_filehandler_extra.zip
uploads_controller.php
37行目あたり。
// set the upload directory
$uploadDir = realpath(TMP).DS;
へ変更。
これで、/tmp/シリアル/データ
みたいな感じでアップされます。
view/index(ctp or thtml)
formヘルパーの扱いが変わっているので、変更。
<?php
/***********************************************
* IMPORTANT *
* for file handler component, do not use any
* helpers ($html->file('userfile')) - this will
* not work. use standard html
* <input type="file" name="userfile">
*/
?>
<?php echo $form->create('Upload',array('enctype' => 'multipart/form-data','action'=>'index')); ?>
<input type="file" name="userfile[]"/>
<br/>
<input type="file" name="userfile[]"/>
<br/>
extra info
<?php echo $form->input('data.extra_field'); ?>
<br/>
<?php
if (isset($uploadData)) {
var_dump($uploadData);
}
if (isset($errorMessage)) {
var_dump($errorMessage);
}
?>
<?php echo $form->end('upload'); ?>
components/file_handler.php
34行目あたり。
/** maxium file size allowed in kb */
var $_maxSize = 30;
を、任意のバイト数へ変更。これでmax sizeが変化するよう。
以上っす。
追記:
realpathの表記は下記のような感じで。
$uploadDir = realpath("../webroot/").DS;
追記2:
index.thtmlの
echo $form->input('data/extra_field');
は、
echo $form->input('data.extra_field');
とするといい感じです。