rfc:curl-file-upload
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:curl-file-upload [2013/01/06 04:38] – [CurlFile proposal] stas | rfc:curl-file-upload [2018/07/03 19:16] (current) – stas | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2013-01-06 | * Date: 2013-01-06 | ||
* Author: Stas Malyshev < | * Author: Stas Malyshev < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
* See also: https:// | * See also: https:// | ||
+ | * Implementation: | ||
This RFC discusses improvement for CURL file uploading option. | This RFC discusses improvement for CURL file uploading option. | ||
- | |||
===== Introduction ===== | ===== Introduction ===== | ||
Line 19: | Line 19: | ||
</ | </ | ||
- | This API is both invonvenient | + | This API is both inconvenient |
===== CurlFile proposal ===== | ===== CurlFile proposal ===== | ||
Line 33: | Line 33: | ||
The curl API will be modified to look for objects of type CurlFile and treat them as entries with @ were previously treated. | The curl API will be modified to look for objects of type CurlFile and treat them as entries with @ were previously treated. | ||
- | ===== CurlFile | + | The file given to CurlFile will not be opened/read until curl_setopt() call. |
+ | ===== CURLFile | ||
+ | <code php> | ||
+ | class CURLFile | ||
+ | { | ||
+ | /** | ||
+ | * Create CurlFile object | ||
+ | * @param string $name File name | ||
+ | * @param string $mimetype Mime type, optional | ||
+ | * @param string $postfilename Post filename, defaults to actual filename | ||
+ | */ | ||
+ | public function __construct($name, | ||
+ | {} | ||
+ | |||
+ | /** | ||
+ | * Set mime type | ||
+ | * @param string $mimetype | ||
+ | * @return CurlFile | ||
+ | */ | ||
+ | public function setMimeType($mimetype) | ||
+ | {} | ||
+ | |||
+ | /** | ||
+ | * Set mime type | ||
+ | * @param string $mimetype | ||
+ | * @return string | ||
+ | */ | ||
+ | public function getMimeType($mimetype) | ||
+ | {} | ||
+ | |||
+ | /** | ||
+ | * Get file name from which the data will be read | ||
+ | * @return string | ||
+ | */ | ||
+ | public function getFilename() | ||
+ | {} | ||
+ | |||
+ | /** | ||
+ | * Get file name which will be sent in the post | ||
+ | * @param string $name File name | ||
+ | * @return string | ||
+ | */ | ||
+ | public function setPostFilename($name) | ||
+ | {} | ||
+ | |||
+ | /** | ||
+ | * Set file name which will be sent in the post | ||
+ | * @return string | ||
+ | * @return CurlFile | ||
+ | */ | ||
+ | public function getPostFilename() | ||
+ | {} | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Also, the functional API to creating CURLFile is provided by request: | ||
+ | |||
+ | <code php> | ||
+ | /** | ||
+ | * Create CURLFile object | ||
+ | * @param string $name File name | ||
+ | * @param string $mimetype Mime type, optional | ||
+ | * @param string $postfilename Post filename, defaults to actual filename | ||
+ | */ | ||
+ | function curl_file_create($name, | ||
+ | {} | ||
+ | </ | ||
+ | |||
+ | This will create a new ```CURLFile``` object just as ```new CURLFile()``` would. | ||
===== Backward compatibility ===== | ===== Backward compatibility ===== | ||
- | In order to assure orderly transition to the use of the new API, the proposal is in 5.5 to leave the @ option working, but make it produce E_DEPRECATED error referring the user to the use of the new API. In 5.6, @ option will be switched off by default, but can still be enabled by explicit curl_setopt setting, such as: | + | A new option is introduced: '' |
- | curl_setopt($curl_handle, | + | <code php> |
+ | curl_setopt($curl_handle, | ||
+ | </ | ||
- | In future versions, this capability may be removed completely. | + | In 5.6, @ option will be switched off by default, but can still be enabled by explicit curl_setopt setting, such as: |
+ | <code php> | ||
+ | curl_setopt($curl_handle, | ||
+ | </ | ||
+ | |||
+ | In future versions, this capability may be removed completely. | ||
===== Optional ===== | ===== Optional ===== | ||
+ | * If upstream cURL API permits, we could add in the future uploading files from string buffers, stream names, stream resources and such, which is now impossible with existing @-based API. The CurlFile API above will then be extended with required functions to support these, such as " | ||
+ | |||
+ | * It is possible to include validation of the file resource given in the constructor, | ||
+ | |||
+ | ===== References ===== | ||
+ | * CURL form API: http:// | ||
+ | * curl_setopt: | ||
+ | * Pull request: https:// | ||
+ | |||
+ | ===== Vote ===== | ||
+ | |||
+ | Voting ended on Monday, January 28th 2013. In order to pass, the requirement is 50%+1 vote, since PHP core language is not changed. The result is: **ACCEPTED**. | ||
+ | |||
+ | < | ||
+ | title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Changelog ===== | ===== Changelog ===== | ||
- | * 2013-01-06 First draft | + | * 2013-01-05 First draft |
+ | * 2013-01-06 Added pull req | ||
+ | * 2013-01-07 Added CURLOPT_SAFE_UPLOAD description | ||
+ | * 2013-01-12 Added curl_file_create() | ||
rfc/curl-file-upload.1357447135.txt.gz · Last modified: 2017/09/22 13:28 (external edit)