파일생성
본문
파일을 생성하는..< br>
objFSO.CreateTextFile(addfile,False,True)< br>
< br>
LINUX와 PHP를 이용해 파일관리자 프로그램을 만들고 싶은데.< br>
디렉토리 생성은 쉽게 해결이 됩니다..< br>
FILE 생성은 어떻게 해야 할까요??< br>
답변 1
먼저 fopen() 함수로 생성하고자 하는 filename을 만듭니다. <br>
$fp=fopen("filename", "w"); // w모드는 새로 만들기, a모드는 파일 존재시 추가.. 존재하지 않으면 새로 만들기 <br>
<br>
다음에 fputs()함수나 fwrite()함수를 사용해서 file에 내용을 씁니다. <br>
fputs($fp, "string"); // --> ascii로 쓰기 <br>
fwrite($fp, "string"); // --> binary로 쓰기 <br>
<br>
마지막으로 fclose()함수로 file생성을 마칩니다. <br>
fclose($fp); <br>
<br>
다음을 참고하세요... <br>
-------------------------------------------- <br>
▶ fopen <br>
-- 파일이나 URL을 연다. <br>
<br>
코드 : int fopen(string filename, string mode); <br>
<br>
설명 : <br>
<br>
If filename begins with "http://" (not case sensitive), an HTTP 1.0 connection is opened to the specified server and a file pointer is returned to the beginning of the text of the response. <br>
<br>
Does not handle HTTP redirects, so you must include trailing slashes on directories. <br>
<br>
If filename begins with "ftp://" (not case sensitive), an ftp connection to the specified server is opened and a pointer to the requested file is returned. If the server does not support passive mode ftp, this will fail. You can open files for either reading and writing via ftp (but not both simultaneously). <br>
<br>
If filename begins with anything else, the file will be opened from the filesystem, and a file pointer to the file opened is returned. <br>
<br>
If the open fails, the function returns false. <br>
<br>
mode may be any of the following: <br>
<br>
'r' - Open for reading only; place the file pointer at the beginning of the file. <br>
'r+' - Open for reading and writing; place the file pointer at the beginning of the file. <br>
'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. <br>
'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. <br>
'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. <br>
'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. <br>
<br>
As well, mode may contain the letter 'b'. This is useful only on systems which differentiate between binary and text files (i.e., it's useless on Unix). If not needed, this will be ignored. Example 1. fopen() example <br>
<br>
$fp = fopen("/home/rasmus/file.txt", "r"); <br>
$fp = fopen("http://www.php.net/", "r"); <br>
$fp = fopen("ftp://user:*** 개인정보보호를 위한 이메일주소 노출방지 ***/", "w"); <br>
<br>
If you are experiencing problems with reading and writing to files and you're using the server module version of PHP, remember to make sure that the files and directories you're using are accessible to the server process. <br>
<br>
On the Windows platform, be careful to escape any backslashes used in the path to the file, or use forward slashes. <br>
<br>
$fp = fopen("c:datainfo.txt", "r"); <br>
<br>
------------------------------------------------------ <br>
<br>
▶ fputs <br>
-- file pointer에 쓴다. <br>
<br>
코드 : int fputs(int fp, string str, int [length]); <br>
<br>
설명 : <br>
<br>
fputs() is an alias to fwrite(), and is identical in every way. Note that the length parameter is optional and if not specified the entire string will be written. <br>
<br>
------------------------------------------------------- <br>
<br>
▶ fwrite <br>
-- 파일을 Binary로 쓴다. <br>
<br>
코드 : int fwrite(int fp, string string, int [length]); <br>
<br>
설명 : <br>
<br>
fwrite() writes the contents of string to the file stream pointed to by fp. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first. <br>
<br>
Note that if the length argument is given, then the magic_quotes_runtime configuration option will be ignored and no slashes will be stripped from string. <br>
<br>
--------------------------------------------------------- <br>
<br>
▶ fclose <br>
-- 지정된 file pointer를 닫는다. <br>
<br>
코드 : int fclose(int fp); <br>
<br>
설명 : <br>
<br>
The file pointed to by fp is closed. <br>
<br>
Returns true on success and false on failure. <br>
<br>
The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen(). <br>
<br>
-----------------------------------------------kldp에서 퍼옴 <br>
도움이 되시길..