お世話になっております。
ファイルをフォルダにアップはできる状態で、編集をするときに、タイトルや内容など文字列は変更可能ですが、ファイルの変更だけがうまくいきません、他のファイルを選択しても、何も起きず、ファイルの名前やファイル自体も変更されないです、どなたかアドバイスいただければと思い投稿いたしました。
よろしくお願いいたします。
UploadsController.php
// 投稿編集
public function edit ($id = null) {
$user = $this->Auth->user('username');
$user = AuthComponent::user('username');
$this->set("user",$user);
$this->Upload->id = $id; if ($this->request->is('get')) { $this->request->data = $this->Upload->read(); } else { if ($this->Upload->save($this->request->data)) { $this->Session->setFlash('編集しました。'); $this->redirect(array('action'=>'my_upload')); } else { $this->Session->setFlash('編集できませんでした。'); } } } // ファイルのアップロード public function add() { $user = $this->Auth->user('username'); $user = AuthComponent::user('username'); $this->set("user",$user); //ファイルをフォルダに保存する if ($this->request->is('post')) { // ユーザーデータの保存 $this->request->data['Upload']['user_id'] = $this->Auth->user('id'); $this->request->data['Upload']['username'] = $this->Auth->user('username'); $tmp = $this->request->data['Upload']['file']['tmp_name']; if(is_uploaded_file($tmp)) { $filename = basename($this->request->data['Upload']['file']['name']); $file = WWW_ROOT.'files'.DS.$filename; if (move_uploaded_file($tmp, $file)) { $this->Upload->create(); $this->request->data['Upload']['filename'] = $filename; if ($this->Upload->saveAll($this->request->data)) { $this->Session->setFlash(__('ア>ップロードしました。')); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('ア>ップロードできませんでした。')); } } } } } }
View/Uploads/add.ctp
<?php echo $this->Form->create('Upload', array('action' => 'add', 'type' => 'file')); echo $this->Form->input('subject', array('label'=>'タイトル')); echo $this->Form->input('Upload.username', array('type'=>'hidden', 'value'=>$user)); echo $this->Form->input('body', array('label'=>'内容','type' => 'textarea')); echo $this->Form->input('qoute','rows' => 3)); echo $this->Form->file('file'); echo $this->Form->end(__('投稿')); ?>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2015/06/09 11:01
2015/06/09 11:08