라이브러리

[PHP] CURLFile::getPostFilename - POST에 대한 파일 이름 가져오기




CURLFile::getPostFilename


`CURLFile::getPostFilename`은 PHP의 `CURLFile` 클래스의 메소드 중 하나입니다. 이 메소드는 업로드 파일의 이름을 반환하는 데 사용됩니다. 업로드 파일은 `CURLFile` 객체를 통해 전송될 수 있습니다.

# 사용법


`CURLFile::getPostFilename` 메소드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

$file = new CURLFile('path/to/file.txt', 'text/plain', 'file.txt');

echo $file->getPostFilename(); // file.txt



# 예제


다음 예제에서는 `CURLFile` 객체를 사용하여 파일을 업로드하는 방법을 보여줍니다.

#hostingforum.kr
php

// 업로드할 파일의 경로

$file_path = 'path/to/file.txt';



// 업로드할 파일의 이름

$file_name = 'file.txt';



// 업로드할 파일의 MIME 타입

$file_mime_type = 'text/plain';



// CURLFile 객체 생성

$file = new CURLFile($file_path, $file_mime_type, $file_name);



// POST 요청을 보내는 CURL 객체 생성

$ch = curl_init('https://example.com/upload');



// POST 요청에 파일을 첨부

curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $file));



// 요청을 보내고 결과를 받기

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);



// 에러가 발생한 경우 에러 메시지를 출력

if (curl_errno($ch)) {

    echo 'Error: ' . curl_error($ch);

}



// 요청을 종료

curl_close($ch);



// 결과를 출력

echo $response;



# 참고


* `CURLFile` 객체는 업로드할 파일을 나타내는 객체입니다.
* `getPostFilename` 메소드는 업로드 파일의 이름을 반환합니다.
* `CURLFile` 객체는 `CURLOPT_POSTFIELDS` 옵션과 함께 사용하여 POST 요청에 파일을 첨부할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 568 페이지

검색

게시물 검색