This shows you the differences between two versions of the page.
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====== | ||
- | |||
- | < | ||
- | |||
- | Check if a file exists | ||
- | |||
- | ====Description==== | ||
- | |||
- | <well size=" | ||
- | < | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | [[file_exists]] ( | ||
- | < | ||
- | <span style=" | ||
- | <span style=" | ||
- | <span style=" | ||
- | </ | ||
- | </ | ||
- | |||
- | Return 1 (true) if the file exists, otherwise return 0 (false) | ||
- | |||
- | ====Parameter==== | ||
- | |||
- | < | ||
- | |||
- | ====Return Value==== | ||
- | |||
- | < | ||
- | |||
- | ====Examples==== | ||
- | |||
- | **Simple existence report:** | ||
- | |||
- | <code php> | ||
- | < | ||
- | if (file_exists("/ | ||
- | print(" | ||
- | } else { | ||
- | print(" | ||
- | } | ||
- | ?></ | ||
- | </ | ||
- | |||
- | **Create a new file with a unique non-conflicting filename** - this example is extracted from the Wattmon OS "/ | ||
- | |||
- | <code php> | ||
- | <? | ||
- | $date=strftime("/ | ||
- | $cnt=0; | ||
- | while (file_exists($date)) { | ||
- | $date=strftime("/ | ||
- | $cnt++; | ||
- | } | ||
- | $st="/ | ||
- | if (file_exists($st)) { | ||
- | $res=rename($st, | ||
- | if ($res==0) $_GLOBALS[' | ||
- | log(" | ||
- | } else { | ||
- | $_GLOBALS[' | ||
- | } | ||
- | print(" | ||
- | ?> | ||
- | </ | ||
- | |||
- | ====See Also==== | ||
- | |||
- | [[findfirst()]] - Start searching the current folder for files matching a pattern and attributes | ||
- | |||
- | [[strftime()]] - Format the passed time using the format < | ||
- | |||
- | [[time()]] - Return the current system timestamp | ||
- | |||
- | [[rename()]] - Rename or move a file from source to destination | ||
- | |||
- | [[log()]] - Print to the System Log | ||
- | |||
- | [[uphp: | ||