
CURLFile::__construct 메서드는 총 3개의 파라미터를 받을 수 있습니다.
1. string $filename: 업로드할 파일의 이름입니다.
2. string $mimetype: 파일의 MIME 타입입니다. (예: text/plain, image/jpeg 등)
3. string $postname: 파일의 이름으로 전송할 이름입니다. (기본값은 filename입니다.)
예를 들어, 다음 코드는 CURLFile::__construct 메서드를 사용하여 파일 업로드를 합니다.
#hostingforum.kr
php
$fp = fopen('example.txt', 'r');
$ch = curl_init('http://example.com/upload');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, new CURLFile('example.txt', 'text/plain', 'example.txt'));
curl_exec($ch);
curl_close($ch);
이 코드는 'example.txt' 파일을 업로드하고, 파일의 이름으로 'example.txt'를 전송합니다.
2025-07-02 07:19