PHP Usage - how to use PHP to program

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
<?xml version = "1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> PHP File Manipulations </title> </head> <body> <h3> File Manipulations </h3> <p> To read, write or append to a file, the file must be opened. At the end of the file access, the file must be closed. <pre> $file = fopen (filepath, access_code); fclose ($file); </pre> The <i>filepath</i> is a string that gives the path and the name of the file. The <i>access_code</i> is a string that gives the mode in which the file is opened. The possible access codes are: <table border = "1" width = "50%"> <tr> <td> "r" </td><td> Read only. The file pointer is positioned at the beginning of the file. </td> </tr> <tr> <td> "w" </td><td> Write only. The file pointer is positioned at the beginning of the file. Previous content of an existing file is erased. Creates a new file if it does not exist. </td> </tr> <tr> <td> "a" </td><td> Write only. The file pointer is positioned to the end of the file. Creates a new file if the file does not exist. </td> </tr> </table> </p> <p> PHP provides several tests on a file. These built-in functions takes the filename as a parameter. <table border = "1" width = "50%"> <tr> <td> file_exists </td> <td> Returns <i>True</i> is file exists. </td> </tr> <tr> <td> is_readable </td> <td> Returns <i>True</i> if the file is readable. </td> </tr> <tr> <td> is_writable </td> <td> Returns <i>True</i> if the file is writable. </td> </tr> <tr> <td> is_executable </td> <td> Returns <i>True</i> if the file is executable. </td> </tr> <tr>
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
<td> is_file </td> <td> Returns <i>True</i> if the file is a file and not a directory. </td> </tr> <tr> <td> filesize </td> <td> Returns the size in bytes </td> </tr> <tr> <td> filemtime </td> <td> Returns the number of days since last modification. </td> </tr> <tr> <td> fileatime </td> <td> Returns the number of days since last access. </td>
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/15/2011 for the course CS 1428 taught by Professor Ali during the Spring '08 term at Texas State.

Page1 / 5

PHP Usage - how to use PHP to program

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online