Home > php教程 > php手册 > body text

file_put_contents() 图片保存 函数成功之后返回值

WBOY
Release: 2016-07-09 09:08:07
Original
1451 people have browsed it

今天弄图片保存时,用到file_put_contents()来保存图片,运行了几次,发下一直没有数据出来,以为是这个函数没操作成功

于是查看了下这个函数的用法和返回值,发现我输出的返回都正确,后来才发现是其他原因引起的

现在分享下这个函数的用法:

file_put_contents() 函数是一次性向文件写入字符串或追加字符串内容的最合适选择。 

file_put_contents() 函数用于把字符串写入文件,成功返回写入到文件内数据的字节数,失败则返回 FALSE。 

语法: 

int file_put_contents ( string filename, string data [, int flags [, resource context]] )
参数说明: 参数 说明 
filename 要写入数据的文件名 
data 要写入的数据。类型可以是 string,array(但不能为多维数组),或者是 stream 资源 
flags 可选,规定如何打开/写入文件。可能的值: 
FILE_USE_INCLUDE_PATH:检查 filename 副本的内置路径 
FILE_APPEND:在文件末尾以追加的方式写入数据 
LOCK_EX:对文件上锁 
 
context 可选,Context是一组选项,可以通过它修改文本属性 

例子: 

echo file_put_contents("test.txt", "This is something.");
?>
运行该例子,浏览器输出: 

18
而 test.txt 文件(与程序同目录下)内容则为:This is something.。

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!