私は現在、php5環境で実行されているcakephp 2.3で開発しています。
blueimp のオリジナル デザイン ( https://github.com/blueimp/jQuery-File-Upload ) に基づいた Jquery ファイル アップロード ( https://github.com/hugodias/FileUpload ) をダウンロードして実装することができました。
すべてが正しく機能しているようです。ただし、ログインしているユーザーの詳細に基づいて、アップロード ディレクトリを動的に変更する必要があります。アップロード コンポーネントは次のとおりです。
class UploadComponent extends Component
{
protected $options;
/*
* $options = array()
* Avaliable Options:
*
*
* $options => array(
* 'upload_dir' => 'files/{your-new-upload-dir}' // Default 'files/'
* )
*/
function __construct( ComponentCollection $collection, $options = null ) {
$this->UploadModel = ClassRegistry::init('FileUpload.Upload');
$this->options = array(
'script_url' => Router::url('/', true).'file_upload/handler',
'upload_dir' => WWW_ROOT.'files/',
'upload_url' => $this->getFullUrl().'/files/',
'param_name' => 'files',
// Set the following option to 'POST', if your server does not support
// DELETE requests. This is a parameter sent to the client:
'delete_type' => 'DELETE',
// The php.ini settings upload_max_filesize and post_max_size
// take precedence over the following max_file_size setting:
'max_file_size' => null,
'min_file_size' => 1,
'accept_file_types' => '/.+$/i', // For only accept images use this: ([^\s]+(\.(?i)(jpg|png|gif|bmp))$)
'max_number_of_files' => null,
// Set the following option to false to enable resumable uploads:
'discard_aborted_uploads' => true,
// Set to true to rotate images based on EXIF meta data, if available:
'orient_image' => false,
'image_versions' => array()
);
# Check if exists new options
if( $options )
{
# Change the upload dir. If it doesn't exists, create it.
if( $options['upload_dir'] )
{
// Remove the first `/` if it exists.
if( $options['upload_dir'][0] == '/' )
{
$options['upload_dir'] = substr($options['upload_dir'], 1);
}
$dir = WWW_ROOT.$options['upload_dir'];
// Create the directory if doesn't exists.
if( !file_exists( $dir) )
{
@mkdir( $dir );
}
$this->options['upload_url'] = $this->getFullUrl().'/'.$dir;
$this->options['upload_dir'] = $dir;
}
}
}
ここで、ログインしたユーザー ID に基づいて、upload_dir を追加するように変更する必要があります。何かのようなもの:
'upload_dir' => WWW_ROOT.'files/'.$this->Session->read('Auth.User.id').'/',
UploadComponent で var $components = array('Session') を宣言しようとしましたが、うまくいきませんでした。
また、upload_dir をハードコーディングするとファイルが作成されないため、ディレクトリの作成が機能していないことも確かです。
私は Cakephp の初心者なので、明らかな手順が見落とされている可能性があります。
よろしく、
クラウド_R