You are here

function HTTP_Request::addFile in Flickr API 5

Adds a file to upload

This also changes content-type to 'multipart/form-data' for proper upload

@access public

Parameters

string name of file-upload field:

mixed file name(s):

mixed content-type(s) of file(s) being uploaded:

Return value

bool true on success

Throws

PEAR_Error

File

phpFlickr/PEAR/HTTP/Request.php, line 585

Class

HTTP_Request
Class for performing HTTP requests

Code

function addFile($inputName, $fileName, $contentType = 'application/octet-stream') {
  if (!is_array($fileName) && !is_readable($fileName)) {
    return PEAR::raiseError("File '{$fileName}' is not readable", HTTP_REQUEST_ERROR_FILE);
  }
  elseif (is_array($fileName)) {
    foreach ($fileName as $name) {
      if (!is_readable($name)) {
        return PEAR::raiseError("File '{$name}' is not readable", HTTP_REQUEST_ERROR_FILE);
      }
    }
  }
  $this
    ->addHeader('Content-Type', 'multipart/form-data');
  $this->_postFiles[$inputName] = array(
    'name' => $fileName,
    'type' => $contentType,
  );
  return true;
}