function read($filename,$filesze)
{
$fp=fopen($filename,"rb");//用fopen rb 属性读取文件并用flock lock_sh,lock_un来解锁
if($fp)
{
flock($fp,LOCK_SH);
clearstatcache();
$filesize=filesize($filename);
if($filesize>0)
{
$data=fread($fp,$filesize);
}else
{
$data=false;
}
flock($fp,LOCK_UN);
fclose($fp);
return $data;
}else
{
return false;
}
}
/**
*用fopen写入文件
*@param string $filename
*@param string $contents
*@return boolean
*/
function wirte($filename,&$contents)
{
$fp=fopen($filename,"wb");
if($fp)
{
flock($fp,LOCK_EX);//同一时间锁定文件,只能一个人操作
fwrite($fp,$contents);
flock($fp,LOCK_UN);//保存数据握进行解锁文件并保存
fclose($fp);
return true;
}else
{
return false;
}
}
//应用 1读文件,2写文件
$body ='';
if( $a = 1 )
{
read('a.txt',1024);
}
else
{
wirte('a.txt',$body);
}
//输出文件
echo $body;
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools
