splitting out Unirest\File and updating README
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__FILE__) . '/Unirest/File.php';
|
||||
require_once dirname(__FILE__) . '/Unirest/Method.php';
|
||||
require_once dirname(__FILE__) . '/Unirest/Response.php';
|
||||
require_once dirname(__FILE__) . '/Unirest/Request.php';
|
||||
|
||||
19
src/Unirest/File.php
Normal file
19
src/Unirest/File.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Unirest;
|
||||
|
||||
class File
|
||||
{
|
||||
/**
|
||||
* Prepares a file for upload. To be used inside the parameters declaration for a request.
|
||||
* @param string $path The file path
|
||||
*/
|
||||
public static function add($filename, $mimetype = '', $postname = '')
|
||||
{
|
||||
if (function_exists('curl_file_create')) {
|
||||
return curl_file_create($filename, $mimetype = '', $postname = '');
|
||||
} else {
|
||||
return sprintf('@%s;filename=%s;type=%s', $filename, $postname ?: basename($filename), $mimetype);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,6 @@ interface Method
|
||||
const OPTIONS = 'OPTIONS';
|
||||
const TRACE = 'TRACE';
|
||||
|
||||
// RFC3744
|
||||
const ACL = 'ACL';
|
||||
|
||||
// RFC3253
|
||||
const BASELINE = 'BASELINE';
|
||||
|
||||
|
||||
@@ -173,19 +173,6 @@ class Request
|
||||
return self::send(Method::TRACE, $url, $body, $headers, $username, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a file for upload. To be used inside the parameters declaration for a request.
|
||||
* @param string $path The file path
|
||||
*/
|
||||
public static function file($filename, $mimetype = '', $postname = '')
|
||||
{
|
||||
if (function_exists('curl_file_create')) {
|
||||
return curl_file_create($filename, $mimetype = '', $postname = '');
|
||||
} else {
|
||||
return sprintf('@%s;filename=%s;type=%s', $filename, $postname ?: basename($filename), $mimetype);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is useful for serializing multidimensional arrays, and avoid getting
|
||||
* the 'Array to string conversion' notice
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Unirest;
|
||||
|
||||
class Response
|
||||
{
|
||||
|
||||
public $code;
|
||||
public $raw_body;
|
||||
public $body;
|
||||
@@ -39,9 +38,8 @@ class Response
|
||||
if (function_exists('http_parse_headers')) {
|
||||
return http_parse_headers($raw_headers);
|
||||
} else {
|
||||
|
||||
$headers = array();
|
||||
$key = '';
|
||||
$headers = array();
|
||||
|
||||
foreach (explode("\n", $raw_headers) as $i => $h) {
|
||||
$h = explode(':', $h, 2);
|
||||
|
||||
Reference in New Issue
Block a user