PHP file_put_contents() 함수
❮ PHP 파일 시스템 참조예시
파일에 데이터 쓰기:
<?php
echo file_put_contents("test.txt","Hello World. Testing!");
?>
위 코드의 출력은 다음과 같습니다.
21
정의 및 사용
file_put_contents()는 파일에 데이터를 씁니다.
이 함수는 파일에 액세스할 때 다음 규칙을 따릅니다.
- FILE_USE_INCLUDE_PATH가 설정된 경우 파일 이름 의 복사본에 대한 포함 경로를 확인하십시오.
- 파일이 없으면 생성
- 파일 열기
- LOCK_EX가 설정된 경우 파일을 잠급니다.
- FILE_APPEND가 설정되어 있으면 파일의 끝으로 이동합니다. 그렇지 않으면 파일 내용 지우기
- 파일에 데이터 쓰기
- 파일을 닫고 잠금 해제
참고: 파일의 기존 내용을 삭제하지 않으려면 FILE_APPEND를 사용하십시오.
통사론
file_put_contents(filename, data, mode, context)
매개변수 값
Parameter | Description |
---|---|
filename | Required. Specifies the path to the file to write to. If the file does not exist, this function will create one |
data | Required. The data to write to the file. Can be a string, array, or a data stream |
mode | Optional. Specifies how to open/write to the file. Possible values:
|
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. |
기술적 세부 사항
반환 값: | 성공 시 파일에 기록된 바이트 수, 실패 시 FALSE |
---|---|
PHP 버전: | 5.0+ |
바이너리 금고: | 네 |
PHP 변경 로그: | PHP 5.1 - LOCK_EX에 대한 지원 추가 및 스트림 리소스를 데이터 매개변수에 전달하는 기능 |
❮ PHP 파일 시스템 참조