User Tools

Site Tools


uphp:functions:fopen

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:fopen [2017/03/17 14:11]
jeff
uphp:functions:fopen [2021/09/13 05:57] (current)
Line 1: Line 1:
 ======fopen====== ======fopen======
 +
 <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>[[fopen]] +<well size="sm"><html> 
-<html>+<span style="font-size:125%;color:green">int 
-<span style="color:green;">string +<span style="color:black">fopen ( 
-<span style="color:blue;">$filename<span style="color:black;">,  +<span style="color:green">string 
-<span style="color:green;">string +<span style="color:blue">$filename<span style="color:black">,  
-<span style="color:blue;">$mode +<span style="color:green">string 
-<span style="color:black;">)+<span style="color:blue">$mode 
 +<span style="color:black">)
 </html></well> </html></well>
  
-Attempt to open a file or stream for reading or writing, and return the file handle for future operations+Attempt to open a file (or special streamfor reading or writing, and return the file handle for future operations
  
 ====Parameters==== ====Parameters====
-<html><span style="color:blue;"><b>filename</b><span style="color:black;"></html>:   If a path is omitted, the current directory will be used to search for the file. Relative paths are supported. Two special file names will open specific streams instead:+ 
 +<html><b><span style="color:blue">$filename<span style="color:black"></b></html>:   If a path is omitted, the current directory will be used to search for the file. Relative paths are supported. Two special file names will open specific streams instead: 
   * 'php:%%//%%stdin' - This will open a stream that will accept characters from a telnet console, allowing for interactive applications responding to keystrokes, when using mode 'r'   * 'php:%%//%%stdin' - This will open a stream that will accept characters from a telnet console, allowing for interactive applications responding to keystrokes, when using mode 'r'
   * 'php:%%//%%stdout' - This will send output characters to the standard output device, such as a telnet console, when using mode 'w'   * 'php:%%//%%stdout' - This will send output characters to the standard output device, such as a telnet console, when using mode 'w'
  
-<html><span style="color:blue;"><b>mode</b><span style="color:black;"></html>:  The following strings are supported:+<html><b><span style="color:blue">$mode<span style="color:black"></b></html>:  The following strings are supported: 
   * 'r' - Open the file (or stream) in read-only mode   * 'r' - Open the file (or stream) in read-only mode
   * 'w' - Open the file (or stream) in write mode, which will overwrite the file   * 'w' - Open the file (or stream) in write mode, which will overwrite the file
   * 'a' - Open the file in append mode for writing, which will open the file and move the pointer to the end of the file   * 'a' - Open the file in append mode for writing, which will open the file and move the pointer to the end of the file
  
-====Return Value==== +====Return Values====
-Upon success it returns a file handle which may be used together with the other file functions that require a handle such as [[fgets()]], [[fwrite()]], [[fclose()]] and [[feof()]]+
  
-If the attempt to open the file or stream fails it will return 0+<html><b><span style="color:green">Integer<span style="color:black"></b></html>:  File handle, or 0 if the attempt to open the file or stream fails
  
 +The file handle may be used together with the other file functions that require a handle such as [[fgets()]], [[fwrite()]], [[fclose()]] and [[feof()]]
  
 ====Example==== ====Example====
 +
 <code php> <code php>
 <? <?
-$f=fopen("/index.cgi","r"); +  $f=fopen("/index.cgi","r"); 
-if ($f) { +  if ($f) { 
-  print("File opened successfully"); +    print("File opened successfully"); 
-  fclose($f); +    fclose($f); 
-} else { +  } else { 
-  print("File open failed"); +    print("File open failed"); 
-}+  }
 ?> ?>
 </code> </code>
  
 ====See Also==== ====See Also====
-[[f485open()]] - Open the RS-485 port as a stream 
  
-[[fseropen()]] - Open the serial port as a stream+[[fseropen()]] - Open the serial port at the specified baud rate with optional parameters
  
-[[fsockopen()]] - Open an internet socket connection+[[f485open()]] - Open the RS-485 port at the specified baud rate and parity
  
-[[fclose()]] - Close a file, stream or socket+[[fsockopen()]] - Open an internet socket connection with optional timeout
  
-[[feof()]] - Test if no more data is available in a file or stream+[[fread()]] - Read bytes from a filestream or socket
  
-[[fgets()]] - Return a single line from a file or stream, with optional size limit+[[fgets()]] - Return a single line from a filestream or socket, with optional size limit
  
-[[fread()]] - Return bytes from a file or stream+[[fwrite()]] - Write data to a filestream or socket
  
-[[fseek()]] - Position the file pointer in an open file+[[tar_put()]] - Add a file to an open file in TAR format
  
-[[ftell()]] - Return current file position in an open file+[[feof()]] - Test if no more data is available in file, stream or socket
  
-[[fwrite()]] - Write data to a file or stream+[[filesize()]] - Return the size of a fileor the number of unread bytes in a stream or socket
  
-[[tar_put()]] - Add a file to an open file in TAR format+[[fseek()]] - Position the file pointer in an open file
  
-[[chdir()]] - Change uPHP'current directory+[[ftell()]] - Return the current position of a file read/write pointer
  
-[[uphp:control_structures:if]] - Flow control structure for conditional execution+[[fclose()]] - Close a file, stream or socket
  
uphp/functions/fopen.1489759884.txt.gz · Last modified: 2021/09/13 05:56 (external edit)