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

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