PHP实现的文件操作类及文件下载功能示例
2018-09-07 15:13
本文实例讲述了PHP实现的文件操作类及文件下载功能。分享给大家供大家参考,具体如下:
文件操作类:
<?php $myfile = new cfile (test.txt); //Now, lets try reading it. echo $myfile->read(); //Then lets try writing to the file. $myfile->write (Hello World!); //Then, lets try appending. $myfile->append (Hello Again!); ?>
文件下载:
<?php $filename = file1.txt; $file = fopen($filename, r); Header(Expires: 0); Header(Pragma: public); Header(Cache-Control: must-revalidate, post-check=0, pre-check=0); Header(Cache-Control: public); Header(Content-Length: . filesize($filename)); Header(Content-Type: application/octet-stream); Header(Content-Disposition: attachment; filename=.$filename); readfile($filename); ?>
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php文件操作总结》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php面向对象程序设计入门教程》、《PHP网络编程技巧总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。