curl_file_create
(PHP 5 >= 5.5.0)
curl_file_create — Create a CURLFile object
Description
This function is an alias of: CURLFile::__construct()
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Другие службы
- Клиентская библиотека работы с URL
- curl_close
- curl_copy_handle
- curl_errno
- curl_error
- curl_escape
- curl_exec
- curl_file_create
- curl_getinfo
- curl_init
- curl_multi_add_handle
- curl_multi_close
- curl_multi_exec
- curl_multi_getcontent
- curl_multi_info_read
- curl_multi_init
- curl_multi_remove_handle
- curl_multi_select
- curl_multi_setopt
- curl_multi_strerror
- curl_pause
- curl_reset
- curl_setopt_array
- curl_setopt
- curl_share_close
- curl_share_init
- curl_share_setopt
- curl_strerror
- curl_unescape
- curl_version
Коментарии
function uploadFile($name,$i=0){
$postField = array();
$tmpfile = $_FILES[$name]['tmp_name'][$i];
$filename = basename($_FILES[$name]['name'][$i]);
$postField['files'] = curl_file_create($tmpfile, $_FILES[$name]['type'][$i], $filename);
$headers = array("Content-Type" => "multipart/form-data");
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'Put here curl API');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_handle, CURLOPT_POST, TRUE);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $postField);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
$returned_fileName = curl_exec($curl_handle);
curl_close($curl_handle);
return json_decode($returned_fileName);
}