User Tools

Site Tools


uphp:functions:file_exists

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

uphp:functions:file_exists [2017/04/10 12:38]
jeff
uphp:functions:file_exists [2021/09/13 05:57]
Line 1: Line 1:
-======file_exists====== 
- 
-<badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge> 
- 
-Check if a file exists 
- 
-====Description==== 
- 
-<well size="sm"> 
-<html> 
-<span style="font-size:125%;color:green">int 
-<span style="color:black"> 
-</html> 
-[[file_exists]] ( 
-<html> 
-<span style="color:green">string 
-<span style="color:blue">$filename 
-<span style="color:black">) 
-</html> 
-</well> 
- 
-Return 1 (true) if the file exists, otherwise return 0 (false) 
- 
-====Parameter==== 
- 
-<html><b><span style="color:blue">$filename<span style="color:black"></b></html>:  Full path and file name to check 
- 
-====Return Value==== 
- 
-<html><b><span style="color:green">Integer<span style="color:black"></b></html> 1 if file exists, 0 if file does not exist 
- 
-====Examples==== 
- 
-**Simple existence report:** 
- 
-<code php> 
-<pre><? 
-  if (file_exists("/test.txt")) { 
-    print("File exists."); 
-  } else { 
-    print("File does not exist!"); 
-  } 
-?></pre> 
-</code> 
- 
-**Create a new file with a unique non-conflicting filename** - this example is extracted from the Wattmon OS "/scripts/logrotate.cgi": 
- 
-<code php> 
-<? 
-  $date=strftime("/logs/log%Y%m%d.txt",time()); // desired filename, but it may already exist 
-  $cnt=0; 
-  while (file_exists($date)) { 
-    $date=strftime("/logs/log%Y%m%d-".$cnt.".txt",time()); // unique non-conflicting filename 
-    $cnt++; 
-  } 
-  $st="/logs/log.txt"; 
-  if (file_exists($st)) { 
-    $res=rename($st,$date); 
-    if ($res==0) $_GLOBALS['sysmsg']="Log file rotated to ".$date; 
-    log("New logfile created after logrotate called."); 
-  } else { 
-    $_GLOBALS['sysmsg']="Unable to rotate, log file doesnt exist"; 
-  } 
-  print("{\"status\":1,\"msg\":\"".$_GLOBALS['sysmsg']."\"}"); 
-?> 
-</code> 
- 
-====See Also==== 
- 
-[[findfirst()]] - Start searching the current folder for files matching a pattern and attributes 
- 
-[[strftime()]] - Format the passed time using the format <html><b><span style="color:green">string<span style="color:black"></b></html> 
- 
-[[time()]] - Return the current system timestamp 
- 
-[[rename()]] - Rename or move a file from source to destination 
- 
-[[log()]] - Print to the System Log 
- 
-[[uphp:uphp_special_variables]] - Special arrays that are populated automatically (including ''$_GLOBALS'') 
  
uphp/functions/file_exists.txt · Last modified: 2021/09/13 05:57 (external edit)