public function storeUpload($name, array $metadata = [])
    {
        if (! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) {
            throw new MongoGridFSException("Could not find uploaded file $name");
        }
        if (! isset($_FILES[$name]['tmp_name'])) {
            throw new MongoGridFSException("Couldn't find tmp_name in the \$_FILES array. Are you sure the upload worked?");
        }

        $uploadedFile = $_FILES[$name];
        $uploadedFile['tmp_name'] = (array) $uploadedFile['tmp_name'];
        $uploadedFile['name'] = (array) $uploadedFile['name'];

        if (count($uploadedFile['tmp_name']) > 1) {
            foreach ($uploadedFile['tmp_name'] as $key => $file) {
                $metadata['filename'] = $uploadedFile['name'][$key];
                $this->storeFile($file, $metadata);
            }

            return null;
        } else {
            $metadata += ['filename' => array_pop($uploadedFile['name'])];
            return $this->storeFile(array_pop($uploadedFile['tmp_name']), $metadata);
        }
    }
public function storeUpload($name, array $metadata = [])
    {
        if (! isset($_FILES[$name]) || $_FILES[$name]['error'] !== UPLOAD_ERR_OK) {
            throw new MongoGridFSException("Could not find uploaded file $name");
        }
        if (! isset($_FILES[$name]['tmp_name'])) {
            throw new MongoGridFSException("Couldn't find tmp_name in the \$_FILES array. Are you sure the upload worked?");
        }

        $uploadedFile = $_FILES[$name];
        $uploadedFile['tmp_name'] = (array) $uploadedFile['tmp_name'];
        $uploadedFile['name'] = (array) $uploadedFile['name'];

        if (count($uploadedFile['tmp_name']) > 1) {
            foreach ($uploadedFile['tmp_name'] as $key => $file) {
                $metadata['filename'] = $uploadedFile['name'][$key];
                $this->storeFile($file, $metadata);
            }

            return null;
        } else {
            $metadata += ['filename' => array_pop($uploadedFile['name'])];
            return $this->storeFile(array_pop($uploadedFile['tmp_name']), $metadata);
        }
    }
public function storeUpload ( $ name , array $ metadata = [ ] ) { if ( ! isset ( $ _FILES [ $ name ] ) || $ _FILES [ $ name ] [ 'error' ] !== UPLOAD_ERR_OK ) { throw new MongoGridFSException ( "Could not find uploaded file $name" ) ; } if ( ! isset ( $ _FILES [ $ name ] [ 'tmp_name' ] ) ) { throw new MongoGridFSException ( "Couldn't find tmp_name in the \$_FILES array. Are you sure the upload worked?" ) ; } $ uploadedFile = $ _FILES [ $ name ] ; $ uploadedFile [ 'tmp_name' ] = ( array ) $ uploadedFile [ 'tmp_name' ] ; $ uploadedFile [ 'name' ] = ( array ) $ uploadedFile [ 'name' ] ; if ( count ( $ uploadedFile [ 'tmp_name' ] ) > 1 ) { foreach ( $ uploadedFile [ 'tmp_name' ] as $ key => $ file ) { $ metadata [ 'filename' ] = $ uploadedFile [ 'name' ] [ $ key ] ; $ this -> storeFile ( $ file , $ metadata ) ; } return null ; } else { $ metadata += [ 'filename' => array_pop ( $ uploadedFile [ 'name' ] ) ] ; return $ this -> storeFile ( array_pop ( $ uploadedFile [ 'tmp_name' ] ) , $ metadata ) ; } }
Saves an uploaded file directly from a POST to the database

@link http://www.php.net/manual/en/mongogridfs.storeupload.php
@param string $name The name attribute of the uploaded file, from <input type="file" name="something"/>.
@param array $metadata An array of extra fields for the uploaded file.
@return mixed Returns the _id of the uploaded file.
@throws MongoGridFSException
Saves an uploaded file directly from a POST to the database