<
?
php
$
data
=
date
(
"Ymd"
)
;
$
dir
=
"/hom/kyle/file/$data"
;
$
filename
=
"/home/kyle/file/$data/testfile"
;
$
filecontent
=
"这是要写入的内容 测试空格 空格
"
;
//判断文件夹是否存在,否则创建
if
(
!
is_dir
(
$
dir
)
)
{
mkdir
(
$
dir
,
0777)
;
}
//判断文件是否存在,否则创建
if
(
!
file_exists
(
$
filename
)
)
{
$
handle
=
fopen
(
$
filename
,
'w'
)
;
if
(
!
$
handle
)
{
echo
'create file fail'
;
exit
;
}
else
{
chmod
(
$
filename
,
0777)
;
}
if
(
fwrite
(
$
handle
,
$
filecontent
)
=
=
=
FALSE
)
{
echo
"can't write into $filename"
;
exit
;
}
fclose
(
$
handle
)
;
}
?
>
php创建文件夹和文件
最新推荐文章于 2023-02-22 20:22:14 发布