CakePHP的3型号形式发送邮件与用户提交的附件

问题描述:

这些是当我做的调试($这个 - >请求 - >数据)CakePHP的3型号形式发送邮件与用户提交的附件

我中省略领域的结果并不重要

我得到这个

[ 
'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

**的https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-file-inputs** – ndm

+0

是的,我想到后,我发布它,它是 echo $ this-> Form-> create($ document,['enctype'=>'multipart/form-data']); – artSir

echo $this->Form->create($document, ['enctype' => 'multipart/form-data']);