search
Homephp教程php手册php fopen函数用法(打开创建文件)

php fopen函数用法(打开创建文件)

Jun 13, 2016 am 11:18 AM
fopenphpfunctioncreateexistOpenTutorialdocumenttimeusage

 

php教程 fopen函数用法(打开创建文件)
在很多时间我们都需要创建文件特别是生成静态页面的时间,我们在php中就常常会用到fopen这个函数来新建文件,它的原是是如何文件存在就追加,不存在可以创建,下面来了很多参数,用你根据自己需要来定义参数。
$xxx = fopen("text.txt", 'w', ture)

*/
$fopen = 'fopen.txt';
$str ='写入一段文件www.bkjia.com';
if( file_exists( $fopen ) )
{
 $h = fopen($fopen,'a+');
 if( fwrite($h,$str) )
 {
  echo '内容增加成功';
 }
 fclose();
}
else
{
 $h = fopen( $fopen,'w+');
 if( fwrite($h,$str))
 {
  echo '文件写入成功';
 }
 fclose();
}

$file = fopen("test.txt","r");
$file = fopen("/home/mb.php100.com/test.txt","r");
$file = fopen("/home/test/test.gif","wb");
$file = fopen("http://www.bkjia.com/","r");
$file = fopen("ftp://user:password@example.com/test.txt","w");


/*
关于fopen函数详细说明

定义和用法
fopen() 函数打开文件或者 url。

如果打开失败,本函数返回 false。

语法
fopen(filename,mode,include_path,context)参数 描述
filename 必需。规定要打开的文件或 url。
mode 必需。规定要求到该文件/流的访问类型。可能的值见下表。
include_path 可选。如果也需要在 include_path 中检索文件的话,可以将该参数设为 1 或 true。
context 可选。规


"r" 只读方式打开,将文件指针指向文件头。
"r+" 读写方式打开,将文件指针指向文件头。
"w" 写入方式打开,将文件指针指向文件头并将文件大小截为零。创建。
"w+" 读写方式打开,将文件指针指向文件头并将文件大小截为零。创建。
"a" 写入方式打开,将文件指针指向文件末尾。文件不存在创建。
"a+" 读写方式打开,将文件指针指向文件末尾。文件不存在创建。

*/
?>


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),