0

私のUsersController.phpで

public function uploadFile() 
{
        $filename = '';
        if ($this->request->is('post')) {


    $uploadData = $this->data['uploadFile']['image'];
            if ( $uploadData['size'] == 0 || $uploadData['error'] !== 0) {
                return false;
            }

            $filename = basename($uploadData['name']);

            if ($this->User->save($filename)) {
                $this->Session->setFlash(__('Your imagename has been saved.'));
            }

            $uploadFolder = WWW_ROOT. 'files';
            $filename = time() .'_'. $filename;
            $uploadPath =  $uploadFolder . DS . $filename;

            if( !file_exists($uploadFolder) ){
                mkdir($uploadFolder);
            }

            if (!move_uploaded_file($uploadData['tmp_name'], $uploadPath)) {
                //$this->set('pdf_path', $fileName);
                return false;
            } 
        }
    }   
}

そして私のuploadfile.ctpで

 <?php
  echo $this->Form->create('uploadFile', array( 'type' => 'file'));
  echo $this->Form->input('image', array('type' => 'file','label' => 'Pdf'));
  echo $this->Form->end('Upload file');
?>

私のデータベースには、テーブル名「image」と他のフィールドがあります。今、ファイル名を db にアップロードできません。

4

1 に答える 1