admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
Derek Allard | afd99ac | 2008-01-19 19:59:14 +0000 | [diff] [blame] | 2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 3 | <head>
|
| 4 |
|
Derek Allard | 404e35d | 2007-08-07 01:00:45 +0000 | [diff] [blame] | 5 | <title>CodeIgniter User Guide : File Helper</title>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
Derek Allard | b341237 | 2007-10-25 12:15:16 +0000 | [diff] [blame] | 13 | <script type="text/javascript" src="../nav/user_guide_menu.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 14 |
|
| 15 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 16 | <meta http-equiv='expires' content='-1' />
|
| 17 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 18 | <meta name='robots' content='all' />
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 19 | <meta name='author' content='ExpressionEngine Dev Team' />
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 20 | <meta name='description' content='CodeIgniter User Guide' />
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 21 |
|
| 22 | </head>
|
| 23 | <body>
|
| 24 |
|
| 25 | <!-- START NAVIGATION -->
|
| 26 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 27 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 28 | <div id="masthead">
|
| 29 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 30 | <tr>
|
Derek Allard | 39b622d | 2008-01-16 21:10:09 +0000 | [diff] [blame] | 31 | <td><h1>CodeIgniter User Guide Version 1.6.0</h1></td>
|
admin | c0d5d52 | 2006-10-30 19:40:35 +0000 | [diff] [blame] | 32 | <td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 33 | </tr>
|
| 34 | </table>
|
| 35 | </div>
|
| 36 | <!-- END NAVIGATION -->
|
| 37 |
|
| 38 |
|
| 39 | <!-- START BREADCRUMB -->
|
| 40 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 41 | <tr>
|
| 42 | <td id="breadcrumb">
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 43 | <a href="http://codeigniter.com/">CodeIgniter Home</a> ›
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 44 | <a href="../index.html">User Guide Home</a> ›
|
| 45 | File Helper
|
| 46 | </td>
|
Derek Allard | bc03091 | 2007-06-24 18:25:29 +0000 | [diff] [blame] | 47 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 48 | </tr>
|
| 49 | </table>
|
| 50 | <!-- END BREADCRUMB -->
|
| 51 |
|
| 52 | <br clear="all" />
|
| 53 |
|
| 54 |
|
| 55 | <!-- START CONTENT -->
|
| 56 | <div id="content">
|
| 57 |
|
| 58 |
|
| 59 | <h1>File Helper</h1>
|
| 60 |
|
| 61 | <p>The File Helper file contains functions that assist in working with files.</p>
|
| 62 |
|
| 63 |
|
| 64 | <h2>Loading this Helper</h2>
|
| 65 |
|
| 66 | <p>This helper is loaded using the following code:</p>
|
| 67 | <code>$this->load->helper('file');</code>
|
| 68 |
|
| 69 | <p>The following functions are available:</p>
|
| 70 |
|
| 71 | <h2>read_file('<var>path</var>')</h2>
|
| 72 |
|
| 73 | <p>Returns the data contained in the file specified in the path. Example:</p>
|
| 74 |
|
| 75 | <code>$string = read_file('./path/to/file.php');</code>
|
| 76 |
|
| 77 | <p>The path can be a relative or full server path. Returns FALSE (boolean) on failure.</p>
|
| 78 |
|
| 79 | <p class="important"><strong>Note:</strong> The path is relative to your main site index.php file, NOT your controller or view files.
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 80 | CodeIgniter uses a front controller so paths are always relative to the main site index.</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 81 |
|
Derek Allard | 4e387c3 | 2007-12-22 16:41:29 +0000 | [diff] [blame] | 82 | <p>If your server is running an open_basedir restriction this function
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 83 | might not work if you are trying to access a file above the calling script.</p>
|
| 84 |
|
| 85 | <h2>write_file('<var>path</var>', <kbd>$data</kbd>)</h2>
|
| 86 |
|
| 87 | <p>Writes data to the file specified in the path. If the file does not exist the function will create it. Example:</p>
|
| 88 |
|
| 89 | <code>
|
| 90 | $data = 'Some file data';<br />
|
| 91 | <br />
|
| 92 | if ( ! write_file('./path/to/file.php', $data))<br />
|
| 93 | {<br />
|
| 94 | echo 'Unable to write the file';<br />
|
| 95 | }<br />
|
| 96 | else<br />
|
| 97 | {<br />
|
| 98 | echo 'File written!';<br />
|
| 99 | }</code>
|
| 100 |
|
Derek Allard | c644128 | 2007-07-04 23:54:32 +0000 | [diff] [blame] | 101 | <p>You can optionally set the write mode via the third parameter:</p>
|
admin | b64b0be | 2006-09-02 17:19:54 +0000 | [diff] [blame] | 102 |
|
| 103 | <code>write_file('./path/to/file.php', $data, <var>'r+'</var>);</code>
|
| 104 |
|
| 105 | <p>The default mode is <kbd>wb</kbd>. Please see the <a href="http://php.net/fopen">PHP user guide</a> for mode options.</p>
|
| 106 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 107 | <p>Note: In order for this function to write data to a file its file permissions must be set such that it is writable (666, 777, etc.).
|
| 108 | If the file does not already exist, the directory containing it must be writable.</p>
|
| 109 |
|
| 110 | <p class="important"><strong>Note:</strong> The path is relative to your main site index.php file, NOT your controller or view files.
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 111 | CodeIgniter uses a front controller so paths are always relative to the main site index.</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 112 |
|
| 113 |
|
| 114 |
|
| 115 | <h2>delete_files('<var>path</var>')</h2>
|
| 116 |
|
| 117 | <p>Deletes ALL files contained in the supplied path. Example:</p>
|
Derek Allard | 4ae3225 | 2007-05-04 11:25:13 +0000 | [diff] [blame] | 118 | <code>delete_files('./path/to/directory/');</code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 119 |
|
| 120 | <p>If the second parameter is set to <kbd>true</kbd>, any directories contained within the supplied root path will be deleted as well. Example:</p>
|
| 121 |
|
Derek Allard | 4ae3225 | 2007-05-04 11:25:13 +0000 | [diff] [blame] | 122 | <code>delete_files('./path/to/directory/', TRUE);</code>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 123 |
|
| 124 | <p class="important"><strong>Note:</strong> The files must be writable or owned by the system in order to be deleted.</p>
|
| 125 |
|
| 126 |
|
admin | e85c05d | 2006-10-23 20:18:34 +0000 | [diff] [blame] | 127 | <h2>get_filenames('<var>path/to/directory/</var>')</h2>
|
| 128 |
|
| 129 | <p>Takes a server path as input and returns an array containing the names of all files contained within it. The file path
|
| 130 | can optionally be added to the file names by setting the second parameter to TRUE.</p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 131 |
|
| 132 |
|
| 133 | </div>
|
| 134 | <!-- END CONTENT -->
|
| 135 |
|
| 136 |
|
| 137 | <div id="footer">
|
| 138 | <p>
|
Derek Allard | 5a34f04 | 2008-01-19 19:41:54 +0000 | [diff] [blame] | 139 | Previous Topic: <a href="email_helper.html">Email Helper</a>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 140 | ·
|
| 141 | <a href="#top">Top of Page</a> ·
|
| 142 | <a href="../index.html">User Guide Home</a> ·
|
Derek Allard | 5a34f04 | 2008-01-19 19:41:54 +0000 | [diff] [blame] | 143 | Next Topic: <a href="form_helper.html">Form Helper</a></p>
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 144 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2007 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 145 | </div>
|
| 146 |
|
| 147 | </body>
|
| 148 | </html> |