public function addUpload(
        $fieldName, $filename, $sendFilename = null, $contentType = null
    ) {
        if (!is_array($filename)) {
            $fileData = $this->fopenWrapper($filename, empty($contentType));
            $this->uploads[$fieldName] = array(
                'fp'        => $fileData['fp'],
                'filename'  => !empty($sendFilename)? $sendFilename
                                :(is_string($filename)? basename($filename): 'anonymous.blob') ,
                'size'      => $fileData['size'],
                'type'      => empty($contentType)? $fileData['type']: $contentType
            );
        } else {
            $fps = $names = $sizes = $types = array();
            foreach ($filename as $f) {
                if (!is_array($f)) {
                    $f = array($f);
                }
                $fileData = $this->fopenWrapper($f[0], empty($f[2]));
                $fps[]   = $fileData['fp'];
                $names[] = !empty($f[1])? $f[1]
                            :(is_string($f[0])? basename($f[0]): 'anonymous.blob');
                $sizes[] = $fileData['size'];
                $types[] = empty($f[2])? $fileData['type']: $f[2];
            }
            $this->uploads[$fieldName] = array(
                'fp' => $fps, 'filename' => $names, 'size' => $sizes, 'type' => $types
            );
        }
        if (empty($this->headers['content-type'])
            || 'application/x-www-form-urlencoded' == $this->headers['content-type']
        ) {
            $this->setHeader('content-type', 'multipart/form-data');
        }

        return $this;
    }
public function addUpload(
        $fieldName, $filename, $sendFilename = null, $contentType = null
    ) {
        if (!is_array($filename)) {
            $fileData = $this->fopenWrapper($filename, empty($contentType));
            $this->uploads[$fieldName] = array(
                'fp'        => $fileData['fp'],
                'filename'  => !empty($sendFilename)? $sendFilename
                                :(is_string($filename)? basename($filename): 'anonymous.blob') ,
                'size'      => $fileData['size'],
                'type'      => empty($contentType)? $fileData['type']: $contentType
            );
        } else {
            $fps = $names = $sizes = $types = array();
            foreach ($filename as $f) {
                if (!is_array($f)) {
                    $f = array($f);
                }
                $fileData = $this->fopenWrapper($f[0], empty($f[2]));
                $fps[]   = $fileData['fp'];
                $names[] = !empty($f[1])? $f[1]
                            :(is_string($f[0])? basename($f[0]): 'anonymous.blob');
                $sizes[] = $fileData['size'];
                $types[] = empty($f[2])? $fileData['type']: $f[2];
            }
            $this->uploads[$fieldName] = array(
                'fp' => $fps, 'filename' => $names, 'size' => $sizes, 'type' => $types
            );
        }
        if (empty($this->headers['content-type'])
            || 'application/x-www-form-urlencoded' == $this->headers['content-type']
        ) {
            $this->setHeader('content-type', 'multipart/form-data');
        }

        return $this;
    }
public function addUpload ( $ fieldName , $ filename , $ sendFilename = null , $ contentType = null ) { if ( ! is_array ( $ filename ) ) { $ fileData = $ this -> fopenWrapper ( $ filename , empty ( $ contentType ) ) ; $ this -> uploads [ $ fieldName ] = array ( 'fp' => $ fileData [ 'fp' ] , 'filename' => ! empty ( $ sendFilename ) ? $ sendFilename : ( is_string ( $ filename ) ? basename ( $ filename ) : 'anonymous.blob' ) , 'size' => $ fileData [ 'size' ] , 'type' => empty ( $ contentType ) ? $ fileData [ 'type' ] : $ contentType ) ; } else { $ fps = $ names = $ sizes = $ types = array ( ) ; foreach ( $ filename as $ f ) { if ( ! is_array ( $ f ) ) { $ f = array ( $ f ) ; } $ fileData = $ this -> fopenWrapper ( $ f [ 0 ] , empty ( $ f [ 2 ] ) ) ; $ fps [ ] = $ fileData [ 'fp' ] ; $ names [ ] = ! empty ( $ f [ 1 ] ) ? $ f [ 1 ] : ( is_string ( $ f [ 0 ] ) ? basename ( $ f [ 0 ] ) : 'anonymous.blob' ) ; $ sizes [ ] = $ fileData [ 'size' ] ; $ types [ ] = empty ( $ f [ 2 ] ) ? $ fileData [ 'type' ] : $ f [ 2 ] ; } $ this -> uploads [ $ fieldName ] = array ( 'fp' => $ fps , 'filename' => $ names , 'size' => $ sizes , 'type' => $ types ) ; } if ( empty ( $ this -> headers [ 'content-type' ] ) || 'application/x-www-form-urlencoded' == $ this -> headers [ 'content-type' ] ) { $ this -> setHeader ( 'content-type' , 'multipart/form-data' ) ; } return $ this ; }
Adds a file to form-based file upload

Used to emulate file upload via a HTML form. The method also sets
Content-Type of HTTP request to 'multipart/form-data'.

If you just want to send the contents of a file as the body of HTTP
request you should use setBody() method.

If you provide file pointers rather than file names, they should support
fstat() and rewind() operations.

@param string                $fieldName    name of file-upload field
@param string|resource|array $filename     full name of local file,
pointer to open file or an array of files
@param string                $sendFilename filename to send in the request
@param string                $contentType  content-type of file being uploaded

@return   HTTP_Request2
@throws   HTTP_Request2_LogicException
Adds a file to form - based file upload