0

これは私のコントローラーです

イメージコントローラー

class Admin_xxxxController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout()->setLayout('admin');
        if ($this->_helper->FlashMessenger->hasMessages()) {
            $messages = $this->_helper->FlashMessenger->getMessages(); 
            $this->view->messages = $messages[0];
        }
    }

    public function preDispatch()
    {
        if(!Zend_Auth::getInstance()->hasIdentity()) {
            if ('login' != $this->getRequest()->getActionName()) {
                $this->_helper->redirector('index','login');
            } else {

        }
    }
    parent::preDispatch();
} 

    public function saveAction()
    {
        try {
            if(isset($_POST['submit'])) {
                $i=0;
                $lmgdata=array();
                foreach($_FILES as $k=>$v){
                    $post=$this->_request->getPost();
                    $path = "images/landimages";
                    $thumb="images/landimages/thumbnails";
                    if(!is_dir($path)){ // to check is folder exist  or not
                        mkdir($path,'0777',true);
                    }

                    if(!is_dir($thumb)){ // to check is folder exist  or not
                        mkdir($thumb,'0777',true);
                    }

           $maxWidth="600";  $maxHeidht="500";$thumbwidth="100";$thumbheidht="75";
            list($width,$height,$y) = getimagesize($v['tmp_name'][$i]);
            $scale   = min($maxWidth/$width, $maxHeidht/$height);

            $scale1   = min($thumbwidth/$width, $thumbheidht/$height);

            $s1=$v['name'][$i];  $destpath = $path.'/'.$s1;  $thumbpath = $thumb.'/'.$s1; 

            if(move_uploaded_file($v['tmp_name'][$i],$destpath)){ 
                    //$this->resize($thumbpath, $destpath,$width, $height,$scale1,1); 
                    $this->resize($destpath, $destpath,$width, $height,$scale,0 );
                    $lmgdata[$i]['lm_image']=$s1; // to save  new image name in  db
                }else{
                    echo "not uploaded"; die();
                }
                $i++;
                }   
            }

                $post=$this->_request->getPost();
                $data=array();
                if($post['land_id'])
                $data['land_id']=$post['land_id'];                  
                $mapper= new Application_Model_xxxMapper();
                $lmmapper= new Application_Model_yyyMapper();

                    if($lid = $mapper->save($data)){
                        $lmmapper->save($lmgdata, $lid);
                        $this->_helper->FlashMessenger(array('success'=>'xxx added Sucessfully'));
                    }else{
                        $this->_helper->FlashMessenger(array('failed'=>'xxx not added ,please try again'));
                    }                       

                $this->_helper->redirector('index','xxxx','admin');                     
        }
        catch(Zend_Db_Exception $e)
            {

        echo $e->getMessage();

            }
}

これは、複数の画像をアップロードする 追加フ​​ォームです。追加フォーム:

    <form action="<?php echo $this->url(array('controller'=>'lands','action'=>'save'),'admin',true);?>" method="post" enctype="multipart/form-data">
    Upload Images:<input type="file" multiple name="land_image[]" id="land_image" class="form-control" autocomplete="off" title="">

コントローラーで for ループを使用して複数の画像を保存し、複数の画像をアップロードして送信しようとしたときにadd form. 保存される画像は 1 つだけで、それもサムネイルのみが保存されます。すべての画像を保存する方法

4

2 に答える 2