PHP Files functions
simple functions
<?php
$docRoot = $_SERVER['DOCUMENT_ROOT'];
//readfile($docRoot."/orders/order.txt"); //do not need fopen
unlink($docRoot."/orders/order.txt");
$fp = fopen($docRoot."/orders/orders.txt",rb);
if($fp){
echo "open ok";
}else{
echo 'error';
}
while (!feof($fp)){
echo fgetc($fp);
}
//fpassthru($fp); //out put string needs fopen
//$len = fwrite($fp,'12345',3);
rewind($fp);
fseek();
fclose($fp);
//file_put_contents($docRoot/orders/order.txt,'123',FILE_APPEND);
Examples
<?php
// create short variable name
$document_root = $_SERVER['DOCUMENT_ROOT'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
@$fp = fopen("$document_root/orders/Book1.csv", 'rb');
flock($fp, LOCK_SH); // lock file for reading
if (!$fp) {
echo "<p><strong>No orders pending.<br />
Please try again later.</strong></p>";
exit;
}
while (!feof($fp)) {
$order= fgets($fp);
echo htmlspecialchars($order)."<br />";
}
flock($fp, LOCK_UN); // release read lock
echo 'Final position of the file pointer is '.(ftell($fp));
echo '<br />';
rewind($fp);
echo 'After rewind, the position is '.(ftell($fp));
echo '<br />';
// while (!feof($fp)) {
//
// $s= fgetcsv($fp,9,',');
// echo "<pre>";
// var_dump($s);
// }
if(is_null($s)) {
echo 'null';
}
fclose($fp);
?>
</body>
</html>
PHP Files functions的更多相关文章
- Creating Your Own PHP Helper Functions In Laravel
By Hamza Ali LAST UPDATED AUG 26, 2018 12,669 104 Laravel provides us with many built-in helper fun ...
- kickstart部署及使用
Linux运维:kickstart : 矮哥linux运维群:93324526 1.环境检查 [root@m01 ~]# cat /etc/redhat-release CentOS release ...
- KICKSTART无人值守安装
1.1 环境说明 [root@test ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@test ~]# uname -r - ...
- kickstart无人值守
笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 高逼格装系统的方法 Kickstar Cobbler 注意,kickstart并不是一个服务的名称,只是装系统的方 ...
- Linux系统优化脚本
#!/bin/bash ############################################################################## # File Na ...
- kickstart ---无人值守安装
kickstart 实战 http://man.linuxde.net/download/CentOS_6_9镜像 安装: 关闭防火墙 且在编辑虚拟网络的vnet8中要取消使用本地dhcp项 1.yu ...
- s32 kickstart 批量自动安装系统
1. 自动安装操作系统 http://blog.oldboyedu.com/autoinstall-kickstart/ 自动安装操作系统的解决方案:kickstart.cobbler(披着web ...
- Kickstart无人值守安装[转载]
导言 作为中小公司的运维,经常会遇到一些机械式的重复工作,例如:有时公司同时上线几十甚至上百台服务器,而且需要我们在短时间内完成系统安装. 常规的办法有什么? 光盘安装系统===>一个服务器DV ...
- kickstart安装步骤
1.1 环境说明 [root@test ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@test ~]# uname -r 2 ...
随机推荐
- pytorch之 classification
import torch import torch.nn.functional as F import matplotlib.pyplot as plt # torch.manual_seed(1) ...
- curl 和 tcpdump
curl: 1.通常使用curl 来监控网址状态, #curl -m 5 -s -o /dev/null -w %{http_code} www.baidu.com #200 -m 设置访问超时时间, ...
- 【2020】DBus,一个更能满足企业需求的大数据采集平台
功能远超Sqoop.DataX.Flume.Logatash.Filebeat等采集工具 注:由于文章篇幅有限,完整文档可扫免费获取 深知其他组件的局限性,才能彰显DBus的优越感 当前有很多数据采集 ...
- mongoose报错:DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
mongoose报错:(node:15689) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes ...
- CentOS与Ubuntu的区别
学习博客:https://www.cnblogs.com/lirongzheng/p/8250511.html 更多Ubuntu相关信息见Ubuntu 专题页面 http://www.linuxidc ...
- package.json(node)中,多个命令行合并一条
1. ‘&’ 并行执行顺序,同时执行 "dev":"node test.js & webpack" 2.'&&'继发顺序,执行前 ...
- ES[7.6.x]学习笔记(一)Elasticsearch的安装与启动
Elasticsearch是一个非常好用的搜索引擎,和Solr一样,他们都是基于倒排索引的.今天我们就看一看Elasticsearch如何进行安装. 下载和安装 今天我们的目的是搭建一个有3个节点的E ...
- Github搜索技巧
按仓库名称.说明或自述文件内容搜索 通过 in 限定符,您可以将搜索限制为仓库名称.仓库说明.自述文件内容或这些的任意组合. 如果省略此限定符,则只搜索仓库名称和说明. 限定符 示例 in:name ...
- Javascript 基础学习(三)js 的原始类型和声明变量
java的基本数据类型一共有 byte short int long float double char boolean js中定义变量使用关键字 var js的原始类型(五个) String: 字符 ...
- GitLab Runner
GitLab Runner是一个开源项目,用于运行你的作业(jobs)并将结果发送回GitLab.它与GitLab CI结合使用,GitLab CI是GitLab用于协调jobs的开源持续集成服务. ...