Exemple #1
0
 /**
  * Call move() method for each given file
  * @return array of filenames that were uploaded
  */
 protected function upload()
 {
     $input = $this->input;
     // if $_FILES array contains fields with multiple attribute
     if (Info::getArrayDepth($input) === 3) {
         foreach ($input as $field => $filebatch) {
             // if current field allows for MULTIPLE files upload
             if (Info::getArrayDepth($filebatch) === 2) {
                 foreach ($filebatch as $file => $contents) {
                     $this->move($contents);
                 }
                 // if current field allows for only SINGLE file upload
             } else {
                 $contents = $filebatch;
                 $this->move($contents);
             }
         }
         // if $_FILES array doesn't contain fields with multiple attribute at all
     } else {
         foreach ($input as $field => $contents) {
             $this->move($contents);
         }
     }
     return $this->results;
 }
Exemple #2
0
 /**
  * Recursively examines $_FILES array depth and rebuilds it accordingly:
  *
  *    $_FILES array
  *        [fieldname for single file upload field] = array with file properties
  *        [fieldname for multiple file upload field] = [
  *                [fileindex] = array with file properties
  *                [fileindex] = array with file properties
  *                [fileindex] = array with file properties
  *        ]
  *        [fieldname for single file upload field] = array with file properties
  *
  * This structure makes much more sense for the purpose of validation.
  *
  *
  * @param array $files - original $_FILES
  * @return array $new - reformed $_FILES
  */
 protected function cleanUpInput($files)
 {
     $new = [];
     foreach ($files as $fieldname => $contents) {
         if (Info::getArrayDepth($contents) === 2) {
             foreach ($contents as $key => $filebatch) {
                 foreach ($filebatch as $fileindex => $value) {
                     $new[$fieldname][$fileindex][$key] = $value;
                 }
             }
         } else {
             foreach ($contents as $key => $value) {
                 $new[$fieldname][$key] = $value;
             }
         }
     }
     return $new;
 }