English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP 기본 강의

PHP 고급 강의

PHP & MySQL

PHP 참조 매뉴얼

PHP curl_file_create() 함수 사용법 및 예제

PHP CURL 참조 매뉴얼

(PHP 5 >= 5.5.0)

curl_file_create — CURLFile 객체 생성

문법

CURLFile curl_file_create ( string $filename [, string $mimetype [, string $postname ]])

업로드 파일을 위해 CURLFile 객체 생성

파라미터

filename

업로드 파일의 경로

mimetype

파일의 Mimetype

postname

파일 이름

반환 값

CURLFile 객체 반환

온라인 예제

curl_file_create() 예제

<?php
/* http://example.com/upload.php:
<?php var_dump($_FILES); ?>
*/
// CURL 핸들 생성
$ch = curl_init('http://example.com/upload.php');
// CURLFile 객체 생성
$cfile = curl_file_create('cats.jpg','image/jpeg','test_name');
// POST 데이터 설정
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// executor 핸들
curl_exec($ch);
?>

이 예제는 다음과 같이 출력됩니다:

array(1) {
  ["test_file"]=>
  array(5) {
    ["name"]=>
    string(9) "test_name"
    ["type"]=>
    string(10) "image/jpeg"
    ["tmp_name"]=>
    string(14) "/tmp/phpPC9Kbx"
    ["error"]=>
    int(0)
    ["size"]=>
    int(46334)
  }
}

PHP CURL 참조 매뉴얼