2016-06-27 3 views
0

여러 이미지 업로드 ZF2를 사용 중입니다. 이는 아래에 하나의 버튼을 파일로 저장하고 하나씩 업로드하려고한다는 의미입니다. 아래 오류가 나타납니다. 오류를 찾으려면 도와주세요. 양식에 파일 태그가 하나만 있으면 같은 코드가 제대로 작동합니다.여러 이미지 zf2에서 하나씩 차례로 업로드

Notice: Array to string conversion in C:\xampp\htdocs\ZendFirstProjectNew1\module\Stall\src\Stall\Controller\StallController.php on line 989

나는 코드의 세부

양식

namespace Stall\Form; 
use Zend\Form\Form; 
use Zend\Db\Adapter\AdapterInterface; 
use Zend\Db\Adapter\Adapter; 
use Doctrine\ORM\EntityManager; 

class MultipleImageForm extends Form 
{ 
    protected $em; 

    public function __construct($name = null) 
    { 
     parent::__construct('stall'); 
     $this->setAttribute("method","post"); 
     $this->setAttribute("enctype","multipart/form-data"); 

     $this->add(array(
      'name' => 'file', 
      'attributes' => array(
       'type' => 'file', 
      ), 
      'options' => array(
       'label' => 'First Image', 
      ), 
     )); 

     $this->add(array(
      'name' => 'image', 
      'attributes' => array(
       'type' => 'file', 
      ), 
      'options' => array(
       'label' => 'Second Image', 
      ), 
     )); 
      $this->add(array(
      'name' => 'submit', 
      'type' => 'submit', 
     )); 
    } 
} 

HTML 아래에있는 여기 붙어

$form->setAttribute('action',$this->url('stall',array('action'=>'multipleimage'))); 
$form->prepare(); 

echo $this->form()->openTag($form); 
echo $this->formRow($form->get('file')); 
echo '<br/>'; 
echo $this->formRow($form->get('image')); 
echo $this->formSubmit($form->get('submit')); 
echo $this->form()->closeTag(); 

컨트롤러

$form = new MultipleImageForm(); 
     $form->get('submit')->setValue('Submit'); 
     $request = $this->getRequest(); 
     if($request->isPost()) 
     { 
      $nonFile = $request->getPost()->toArray(); 
      $File = $this->params()->fromFiles('file'); 
      $data = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); 
     // print_r($data);die; 
      //set data post and file ... 
      $form->setData($data); 
      if ($form->isValid()) 
      { 

       $result = new ImageUpload(); 
       $image1 = (string) $data['file']['name']; 
       $image2 = (string) $data['image']['name']; 

       if(!empty($image1)) 
       { 
        $adapter = new \Zend\File\Transfer\Adapter\Http(); 
        $adapter->setDestination('public/img/upload/'); // Returns all known internal file information 
        $adapter->addFilter('File\Rename', array('target' => $adapter->getDestination() . DIRECTORY_SEPARATOR .$image1 , 'overwrite' => true)); 
        //$adapter->addFilter('File\Rename', array('target' => $adapter->getDestination() . DIRECTORY_SEPARATOR."_upload123".$favicon , 'overwrite' => true)); 
        if(!$adapter->receive()) 
        { 
         $messages = $adapter->getMessages(); 
        } 
        else 
        { 
         echo "Image Uploaded"; 
        } 
       } 

       if(!empty($image2)) 
       { 
        $adapter = new \Zend\File\Transfer\Adapter\Http(); 
        $adapter->setDestination('public/img/upload/'); // Returns all known internal file information 
        $adapter->addFilter('File\Rename', array('target' => $adapter->getDestination() . DIRECTORY_SEPARATOR .$image2 , 'overwrite' => true)); 
        //$adapter->addFilter('File\Rename', array('target' => $adapter->getDestination() . DIRECTORY_SEPARATOR."_upload123".$favicon , 'overwrite' => true)); 
        if(!$adapter->receive()) 
        { 
         $messages = $adapter->getMessages(); 
        } 
        else 
        { 
         echo "Image Uploaded"; 
        } 
       } 
      } 

     } 
     return array('form' => $form); 
+0

컨트롤러에서'989' 라인은 어느 것입니까? – Wilt

+0

$ adapter-> addFilter ('File \ Rename', array ('target'=> $ adapter-> getDestination() .DIRECTORY_SEPARATOR. $ image1, 'overwrite'=> true)); 989 – BeDeveloper

답변

0

컨트롤러 라인 989이 줄 경우 :

$adapter->addFilter('File\Rename', array('target' => $adapter->getDestination() . DIRECTORY_SEPARATOR .$image1 , 'overwrite' => true)); 

가 그리고 당신이 오류 얻을 : 그 선은이다에 그런

Notice: Array to string conversion in C:\xampp\htdocs\ZendFirstProjectNew1\module\Stall\src\Stall\Controller\StallController.php on line 989

변수 중 하나를 문자열 대신 배열 :

따라서 $adapter->getDestination() 또는 $image1은 string 유형이 아닙니다. 코드와 리펙터를 디버깅하여 두 변수에 대한 문자열을 얻을 수 있도록해야한다.

+0

$ adapter-> getDestination() 배열이었습니다. 배열로 수정했지만 하나의 이미지가 업로드되고 오류가 발생합니다 ([fileUploadErrorAttack] => File 'php1013.tmp_c-300x229.jpg'가 불법 업로드되었습니다). 이것은 가능한 공격 일 수 있습니다.) – BeDeveloper

+0

@BeDeveloper 그것은 또 다른 질문입니다. – Wilt

+0

나는 지난 이틀 동안 막혔다. 지금 무엇을 해야할지? – BeDeveloper

관련 문제