php创建临时文件tempnam与tmpfile区别
tempnam() 函数创建一个具有唯一文件名的临时文件。 若成功,则该函数返回新的临时文件名。若失败,则返回 false。
tempnam() 函数创建一个具有唯一文件名的临时文件。
若成功,则该函数返回新的临时文件名。若失败,则返回 false。
语法
tempnam(dir,prefix)
*/
function dir_wriable($dir) //自定义函数扩展建立临时文件
{
$test=tempnam("$dir","test_file"); //建立临时文件
if(fopen($test,"w">$fp=@fopen($test,"w")) //如果文件成功打开
{
@fclose($fp); //关闭文件
@unlink($test); //删除文件
$wriable="ture"; //返回值为真
}
else
{
$wriable=false or die("cannot open $test!"); //返回值为假
}
return $wriable; //返回布尔型值
}
if(dir_wriable(str_replace('//','/',dirname(__file__)))) //调用自定义函数
{
$dir_wriable='建立文件成功';
}
else
{
$dir_wriable='建立文件失败';
}
/*
如果 php教程 不能在指定的 dir 参数中创建文件,则退回到系统默认值。
注释:本函数的行为在 4.0.3 版中改变了。也会建立一个临时文件以避免竞争情形,即有可能会在产生出作为文件名的字符串与脚本真正建立该文件之间会在文件系统中存在同名文件。注意,如果不再需要该文件则要删除此文件,不会自动删除的。
tmpfile() 函数以读写(w+)模式建立一个具有唯一文件名的临时文件。
文件会在关闭后(用 fclose())自动被删除,或当脚本结束后。
*/
$temp = tmpfile();
fwrite($temp, "testing, testing.");
//倒回文件的开头
rewind($temp);
//从文件中读取 1k
echo fread($temp,1024);
//删除文件
fclose($temp);

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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),

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

Dreamweaver Mac version
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
