php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
curl_file.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Stanislav Malyshev <stas@php.net> |
14 +----------------------------------------------------------------------+
15 */
16
17#ifdef HAVE_CONFIG_H
18# include "config.h"
19#endif
20
21#include "php.h"
23#include "curl_private.h"
24#include "curl_file_arginfo.h"
25
28
29static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
30{
31 zend_string *fname, *mime = NULL, *postname = NULL;
32 zval *cf = return_value;
33
35 Z_PARAM_PATH_STR(fname)
38 Z_PARAM_STR_OR_NULL(postname)
40
41 zend_update_property_str(curl_CURLFile_class, Z_OBJ_P(cf), "name", sizeof("name")-1, fname);
42
43 if (mime) {
44 zend_update_property_str(curl_CURLFile_class, Z_OBJ_P(cf), "mime", sizeof("mime")-1, mime);
45 }
46
47 if (postname) {
48 zend_update_property_str(curl_CURLFile_class, Z_OBJ_P(cf), "postname", sizeof("postname")-1, postname);
49 }
50}
51
52/* {{{ Create the CURLFile object */
53ZEND_METHOD(CURLFile, __construct)
54{
57}
58/* }}} */
59
60/* {{{ Create the CURLFile object */
66/* }}} */
67
68static void curlfile_get_property(const char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
69{
70 zval *res, rv;
71
75}
76
77static void curlfile_set_property(const char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
78{
80
84
86}
87
88/* {{{ Get file name */
89ZEND_METHOD(CURLFile, getFilename)
90{
91 curlfile_get_property("name", sizeof("name")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
92}
93/* }}} */
94
95/* {{{ Get MIME type */
96ZEND_METHOD(CURLFile, getMimeType)
97{
98 curlfile_get_property("mime", sizeof("mime")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
99}
100/* }}} */
101
102/* {{{ Get file name for POST */
103ZEND_METHOD(CURLFile, getPostFilename)
104{
105 curlfile_get_property("postname", sizeof("postname")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
106}
107/* }}} */
108
109/* {{{ Set MIME type */
111{
112 curlfile_set_property("mime", sizeof("mime")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
113}
114/* }}} */
115
116/* {{{ Set file name for POST */
117ZEND_METHOD(CURLFile, setPostFilename)
118{
119 curlfile_set_property("postname", sizeof("postname")-1, INTERNAL_FUNCTION_PARAM_PASSTHRU);
120}
121/* }}} */
122
124{
125 zend_string *data, *postname, *mime = NULL;
126 zval *object;
127
128 object = ZEND_THIS;
129
132 Z_PARAM_STR(postname)
134 Z_PARAM_STR(mime)
136
137 zend_update_property_str(curl_CURLStringFile_class, Z_OBJ_P(object), "data", sizeof("data") - 1, data);
138 zend_update_property_str(curl_CURLStringFile_class, Z_OBJ_P(object), "postname", sizeof("postname")-1, postname);
139 if (mime) {
140 zend_update_property_str(curl_CURLStringFile_class, Z_OBJ_P(object), "mime", sizeof("mime")-1, mime);
141 } else {
142 zend_update_property_string(curl_CURLStringFile_class, Z_OBJ_P(object), "mime", sizeof("mime")-1, "application/octet-stream");
143 }
144}
145
147{
148 curl_CURLFile_class = register_class_CURLFile();
149
150 curl_CURLStringFile_class = register_class_CURLStringFile();
151}
curl_file_create(string $filename, ?string $mime_type=null, ?string $posted_filename=null)
PHP_CURL_API zend_class_entry * curl_CURLFile_class
Definition curl_file.c:26
void curlfile_register_class(void)
Definition curl_file.c:146
PHP_CURL_API zend_class_entry * curl_CURLStringFile_class
Definition curl_file.c:27
zend_string * res
Definition ffi.c:4692
zval * arg
Definition ffi.c:3975
#define NULL
Definition gdcache.h:45
#define PHP_FUNCTION
Definition php.h:364
#define PHP_CURL_API
Definition php_curl.h:32
zend_constant * data
zval rv
Definition session.c:1024
#define INTERNAL_FUNCTION_PARAMETERS
Definition zend.h:49
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
Definition zend.h:50
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
Definition zend_API.c:1849
ZEND_API zval * zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv)
Definition zend_API.c:5201
ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value)
Definition zend_API.c:5066
ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value)
Definition zend_API.c:5057
#define Z_PARAM_PATH_STR(dest)
Definition zend_API.h:2041
#define RETURN_COPY_DEREF(zv)
Definition zend_API.h:1056
#define ZEND_PARSE_PARAMETERS_END()
Definition zend_API.h:1641
#define Z_PARAM_STR_OR_NULL(dest)
Definition zend_API.h:2089
#define ZEND_PARSE_PARAMETERS_NONE()
Definition zend_API.h:1623
#define Z_PARAM_OPTIONAL
Definition zend_API.h:1667
#define Z_PARAM_STR(dest)
Definition zend_API.h:2086
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
Definition zend_API.h:1620
#define ZEND_METHOD(classname, name)
Definition zend_API.h:76
#define ZEND_THIS
Definition zend_API.h:523
struct _zval_struct zval
struct _zend_string zend_string
struct _zend_class_entry zend_class_entry
#define Z_OBJ_P(zval_p)
Definition zend_types.h:990
zval * return_value
zend_string * name
object