| 
       tempnam() 函数创建一个具有唯一文件名的临时文件,若成功,则该函数返回新的临时文件名,若失败,则返回false。 
语法:tempnam(dir,prefix) 
	
	- function dir_wriable($dir)          
 
	- { 
 
	-   $test=tempnam("$dir","test_file");        
 
	-   if($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); 
 
	-  
 
	- echo fread($temp,1024); 
 
	-  
 
	- fclose($temp); 
 
	 
 
 
      
      (责任编辑:admin) |