这些是我调试时的结果($ this-> request-> data)
我省略了无关紧要的字段
我明白了
[
'file' => 'Atest.doc'
]
我想要这个
[
'file' => [
'tmp_name' => '/Applications/MAMP/tmp/php/phpgBEFye',
'error' => (int) 0,
'name' => 'Atest.doc',
'type' => 'application/msword',
'size' => (int) 45056
]
这是.ctp
echo $this->Form->create($contact, ['id'=>'contact-form']);
echo $this->Form->file('file', ['label'=> 'Cover Letter']);
echo $this->Form->button('Send');
echo $this->Form->end();
我的联系人控制器
<?php
namespace App\Controller;
use App\Controller\AppController;
use App\Form\ContactForm;
use Cake\ORM\TableRegistry;
use Cake\Mailer\Email;
use Cake\Network\Exception\SocketException;
use Burzum\FileStorage\Storage\StorageManager;
public function index($option = 'index'){
$contact = new ContactForm();
if ($this->request->is('post')) {
if ($contact->execute($this->request->getData())) {
//debug($this->request->getData() );
}
}
///..I omitted the rest
}
答案 0 :(得分:0)
echo $this->Form->create($document, ['enctype' => 'multipart/form-data']);