php - Ignore Empty instances of File upload With Zend Framework ? File not uploading because of it -


i trying upload several files in zf1

there 2 options upload; audio or image. when attempt upload images empty instance of file_audio having issues.

this print $_files

array (     [image_file] => array         (             [name] => boss.jpg             [type] => image/jpeg             [tmp_name] => c:\windows\temp\phpa01.tmp             [error] => 0             [size] => 37246             [options] => array                 (                     [ignorenofile] =>                      [usebytestring] => 1                     [magicfile] =>                      [detectinfos] => 1                 )              [validated] =>              [received] =>              [filtered] =>              [validators] => array                 (                     [0] => zend_validate_file_upload                 )          )      [audio_file] => array         (             [name] =>              [type] =>              [tmp_name] =>              [error] => 4             [size] =>              [options] => array                 (                     [ignorenofile] =>                      [usebytestring] => 1                     [magicfile] =>                      [detectinfos] => 1                 )              [validated] =>              [received] =>              [filtered] =>              [validators] => array                 (                     [0] => zend_validate_file_upload                 )         ) ) 

this zend code works when both files selected

if (! empty ( $post ['type'] )) {      $adapter = new zend_file_transfer ();  //  echo "<pre>"; print_r($_files);   "</pre>"; exit;      if ($post ['type'] == 'image' && ! empty ( $_files ['image_file'] ['name'] )) {          $files = $adapter->getfileinfo();           echo "<pre>"; print_r($files);   "</pre>"; exit;         $files = $adapter->getfileinfo();          $files_path = $config->topic_images->path;           // limit mime type of given files gif , jpeg images //      $adapter->addvalidator ( 'mimetype', false, array ('image/jpeg', 'image/png', 'image/jpg' ) );  //      $adapter->addvalidator ( 'extension', false, 'png,jpeg,jpg' );  //      $adapter->addvalidator ( 'filessize', false, array ('min' => '1kb', 'max' => '5mb' ) );  //      $adapter->addvalidator ( 'imagesize', false, array ('minwidth' => 0, 'maxwidth' => 800, 'minheight' => 0, 'maxheight' => 800 ) );  // limit size of image height of 100-200 , width of 40-80 pixel       }elseif($post ['type'] == 'audio' && ! empty ( $_files ['audio_file'] ['name'] )) {          $files_path = $config->topic_audio->path;      }elseif($post ['type'] == 'video' && ! empty ( $post ['video_file'] )) {      }   $files = $adapter->getfileinfo ();  $file_name = null; $tmparr = null;  $fname = null; $fext = null;           foreach ( $files['image_file'] $file => $info ) {     if (! empty ( $info ['name'] )) {         $fname = substr ( $info ['name'], 0, strrpos ( $info ['name'], "." ) );         $fext = substr ( $info ['name'], strrpos ( $info ['name'], "." ) );     } }       if (! empty ( $fname )) {      $file_name = $fname . "-" . $post ['topic_id'] . $fext;      $horrible_chars = array ("~", "@", "#", "$", "%", "^", "&", "*", "(", ")", " " ); echo     $cleanfilename = str_replace ( $horrible_chars, "", $file_name );       $adapter->setdestination ( $files_path );  //  $adapter->addfilter ( 'rename', array ('target' => $files_path . ds . $cleanfilename, 'overwrite' => true ) );        if ($adapter->receive ()) {      //  echo "xxx"; exit;          $post ['filename'] = $cleanfilename;         $result = $topicmodel->updatetopicassociation ( $post );         $old_file = $files_path . ds . $post ['existing_file'];          if (file_exists ( $old_file )) {             if ($file_name != $post ['existing_file']) {                 @unlink ( $old_file );             }         }          $this->_flashmessenger->addmessage ( 'topic '.$post['type'].'added successfully' );     } else {       $errors = $adapter->geterrors();     print_r($errors); exit;          $post ['filename'] = null;         $res_delete = $topicmodel->updatetopicassociation ( $post ['topic_id'] );         $this->_flashmessenger->addmessage ( 'error(s) encountered. file association not updated.' );     } }  //    else { //      if (! empty ( $post ['chkdelete'] ) && $post ['chkdelete'] == 1) { //          $post ['filename'] = null; //          $result = $jobmodel->updatejoblogo ( $post ); //          $old_file = $files_path . ds . $post ['c_image_name']; //           //          if (file_exists ( $old_file )) { //              @unlink ( $old_file ); //          } //      } //    } } 

i've spent whole day trying upload image or audio file. have idea problem be?

updated form inputs baseurl(). "/" . $this->modulename; ?>/topic/action); ?>">

      <input type="file" id="image_file" name="image_file">     </form>     <input type="text" name="video_file"  size="50" id="video_file" /> 

try set ignorenofile option true, adapter won't throw fit if there no file:

$adapter = new zend_file_transfer ('http', false, array('ignorenofile'=>true)); 

or

$adapter = new zend_file_transfer (); $adapter->setoptions(array('ignorenofile'=>true)) 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -