Phalcon Upload Multiple Files

phalcon view into variable

Form

<form target='controller/action' method='post' enctype='multipart/form-data' >
  <input type="file" name="files[]" multiple />
  <input type="submit" value="save" />
</form>

Server Side


public $extIMG = array(
        'image/jpeg',
        'image/png',
        'image/bmp',
        'application/pdf',
    );
...

public function actionAction(){
    if( $this->request->hasFiles() == true){
        foreach( $this->request->getUploadedFiles() as $file){              
            if ( in_array($file->getType() , $this->extIMG) && $file->getError() == 0 ){
                $Name      = preg_replace("/[^A-Za-z0-9.]/", '-', $file->getName() );
                $FileName  = "/some/path/to/pdfs" . $Name;

                switch( strtolower($file->getExtension()) ){
                    case "pdf":
                    if(!$file->moveTo($FileName)){   
                        $this->flash->error("Ada error");
                        return $this->dispatcher->forward(
                          array(
                              "controller" => "incident`",
                              "action" => "new",
                          ));
                    }
                    break;
                }
            }   
         }
    }
}


masih bingung boleh kontak ane gan... 08975835238 (WA)
Shorten URL :
Share this Story: