라이브러리
[PHP] CURLFile::getFilename - 파일 이름 가져오기
CURLFile::getFilename
CURLFile::getFilename은 CURLFile 클래스의 메소드로, 파일의 이름을 반환합니다. 이 메소드는 CURLFile 객체가 생성될 때 파일의 이름을 지정할 때 사용됩니다.
사용 방법
CURLFile::getFilename 메소드는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$file = new CURLFile('example.txt', 'text/plain', 'example');
echo $file->getFilename(); // example
예제
# 1. 파일 업로드
CURLFile::getFilename 메소드는 파일 업로드 시 파일의 이름을 반환할 때 유용합니다.
#hostingforum.kr
php
// 업로드할 파일의 경로와 이름을 지정합니다.
$file_path = 'example.txt';
$file_name = 'example';
// CURLFile 객체를 생성합니다.
$file = new CURLFile($file_path, 'text/plain', $file_name);
// 파일 업로드를 위한 CURL 요청을 생성합니다.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/upload');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $file));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 파일 업로드를 요청합니다.
$response = curl_exec($ch);
// 파일 업로드 결과를 출력합니다.
echo $response;
# 2. 파일 다운로드
CURLFile::getFilename 메소드는 파일 다운로드 시 파일의 이름을 반환할 때 유용합니다.
#hostingforum.kr
php
// 다운로드할 파일의 URL을 지정합니다.
$url = 'http://example.com/download';
// CURL 요청을 생성합니다.
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// 파일 다운로드를 요청합니다.
$response = curl_exec($ch);
// 파일 다운로드 결과를 저장합니다.
$file_path = 'downloaded_file.txt';
$file = fopen($file_path, 'wb');
fwrite($file, $response);
fclose($file);
// 파일의 이름을 출력합니다.
echo $file->getFilename(); // downloaded_file.txt
참고
CURLFile::getFilename 메소드는 CURLFile 객체가 생성될 때 파일의 이름을 지정할 때 사용됩니다. 파일의 이름을 지정하지 않은 경우, 파일의 이름은 CURLFile 객체의 파일 경로에서 추출됩니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.