Call to undefined function curl_file_create() [file handling]

只愿长相守 提交于 2021-02-17 04:52:19

问题


I'm trying to upload a file with curl, and in the PHP documentation it says:

To post a file, prepend a filename with @ and use the full path. The filetype can be explicitly specified by following the filename with the type in the format ';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option with the @ prefix. As of PHP 5.5.0, the @ prefix is deprecated and files can be sent using CURLFile.

So I try using CURLFile instead, whereas I get the error

Call to undefined function curl_file_create()

so - then I try to locate the class CURLFile with var_dump(class_exists('curlfile'));

But it says that it doesn't. I wonder - is CURLFile something one has to install manually? And is it better to use the @path/to/file;type=mime instead, even though it will be deprecated soon enough?

Thank you

To clairy - curl is installed and works. It's only the file-handling mumbo jumbo that doesn't seem to exist on my system.

I don't add any code, cause there is no code to add. I run curl_file_create() and get the answer that the function doesn't exists, even though curl itself works.


回答1:


I do not use "curl_file_create" and "CurlFile", I prefer to use "@/file_name_with_full_path".

See the reference links and use these other methods for file upload via POST method via CURL via PHP.

Send a file via post with curl and PHP




回答2:


PHP must have been compiled with the --with-curl switch for this function to be available. Check your phpinfo() output to verify what switches your PHP was compiled with.

If you are on Linux then check your distribution's packages as Curl support may be provided by a module instead. (For example, on Debian one must install the php5-curl package.)


Note that curl_file_create() was added in PHP 5.5.0. If your PHP installation is older, it will not support this function.




回答3:


if you are using xampp or wamp than you have to update php.ini file to enable curl because apache has separate php.ini file in its folder which it uses.the web server php.ini file is different from the php.ini in php installation folder.



来源:https://stackoverflow.com/questions/18363384/call-to-undefined-function-curl-file-create-file-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!