file_uploading.html 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>File Uploading Class &mdash; CodeIgniter 3.1.11 documentation</title>
  8. <link rel="shortcut icon" href="../_static/ci-icon.ico"/>
  9. <link href='https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic|Roboto+Slab:400,700|Inconsolata:400,700&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
  10. <link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
  11. <link rel="index" title="Index"
  12. href="../genindex.html"/>
  13. <link rel="search" title="Search" href="../search.html"/>
  14. <link rel="top" title="CodeIgniter 3.1.11 documentation" href="../index.html"/>
  15. <link rel="up" title="Libraries" href="index.html"/>
  16. <link rel="next" title="Form Validation" href="form_validation.html"/>
  17. <link rel="prev" title="Encryption Library" href="encryption.html"/>
  18. <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
  19. </head>
  20. <body class="wy-body-for-nav" role="document">
  21. <div id="nav">
  22. <div id="nav_inner">
  23. <div id="pulldown-menu" class="ciNav">
  24. <ul>
  25. <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
  26. </ul>
  27. <ul>
  28. <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
  29. <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
  30. <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
  31. <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
  32. <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
  33. </ul>
  34. </li>
  35. </ul>
  36. <ul>
  37. <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
  38. <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
  39. <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
  40. <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
  41. <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
  42. <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
  43. <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
  44. </ul>
  45. </li>
  46. </ul>
  47. <ul>
  48. <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
  49. <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
  50. <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
  51. <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
  52. <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
  53. </ul>
  54. </li>
  55. </ul>
  56. <ul>
  57. <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
  58. <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
  59. <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
  60. </ul>
  61. </li>
  62. </ul>
  63. <ul>
  64. <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
  65. <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
  66. <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
  67. <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
  68. <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
  69. <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
  70. <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
  71. <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
  72. <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
  73. <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
  74. <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
  75. <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
  76. <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
  77. <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
  78. <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
  79. <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
  80. <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
  81. <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
  82. <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
  83. <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
  84. <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
  85. <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
  86. <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
  87. <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
  88. <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
  89. <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
  90. <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
  91. </ul>
  92. </li>
  93. </ul>
  94. <ul class="current">
  95. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current">
  96. <li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li>
  97. <li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li>
  98. <li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li>
  99. <li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li>
  100. <li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li>
  101. <li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li>
  102. <li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li>
  103. <li class="toctree-l2"><a class="reference internal" href="encryption.html">Encryption Library</a></li>
  104. <li class="toctree-l2 current"><a class="current reference internal" href="#">File Uploading Class</a></li>
  105. <li class="toctree-l2"><a class="reference internal" href="form_validation.html">Form Validation</a></li>
  106. <li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li>
  107. <li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li>
  108. <li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li>
  109. <li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li>
  110. <li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li>
  111. <li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li>
  112. <li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li>
  113. <li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li>
  114. <li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li>
  115. <li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li>
  116. <li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li>
  117. <li class="toctree-l2"><a class="reference internal" href="sessions.html">Session Library</a></li>
  118. <li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li>
  119. <li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li>
  120. <li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li>
  121. <li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li>
  122. <li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li>
  123. <li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li>
  124. <li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
  125. <li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li>
  126. </ul>
  127. </li>
  128. </ul>
  129. <ul>
  130. <li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
  131. <li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
  132. <li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
  133. <li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
  134. <li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
  135. <li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
  136. <li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
  137. <li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
  138. <li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
  139. <li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
  140. <li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
  141. <li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
  142. <li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
  143. <li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
  144. <li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
  145. </ul>
  146. </li>
  147. </ul>
  148. <ul>
  149. <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
  150. <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
  151. <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
  152. <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
  153. <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
  154. <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
  155. <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
  156. <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
  157. <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
  158. <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
  159. <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
  160. <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
  161. <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
  162. <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
  163. <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
  164. <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
  165. <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
  166. <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
  167. <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
  168. <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
  169. <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
  170. <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
  171. </ul>
  172. </li>
  173. </ul>
  174. </div>
  175. </div>
  176. </div>
  177. <div id="nav2">
  178. <a href="#" id="openToc">
  179. <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAAAf/bAIQABAMDAwMDBAMDBAYEAwQGBwUEBAUHCAYGBwYGCAoICQkJCQgKCgwMDAwMCgwMDQ0MDBERERERFBQUFBQUFBQUFAEEBQUIBwgPCgoPFA4ODhQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAKwCaAwERAAIRAQMRAf/EAHsAAQAABwEBAAAAAAAAAAAAAAABAwQFBgcIAgkBAQAAAAAAAAAAAAAAAAAAAAAQAAEDAwICBwYEAgsAAAAAAAIBAwQAEQUSBiEHkROTVNQWGDFBUVIUCHEiMtOUFWGBobHRQlMkZIRVEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwDSC+ygkOOaUoKigUCgUCgUCgUCgUCgUCgUCgkuGguIP9FBMFb0Hqg7We+3jlmIqqYFf4ub+/QYlnOR/LqIBKGFUbf8qWv971BytQXXE7Y3Lnm3HsFhp2TaZJAdchRXpIgSpdEJWxJEW3xoKV7F5OMy7JkQn2o7D6w33XGjEAkoiqrJEqIiOIiKuhePCgqp22dyYyS3CyWHnQ5joG61HkRnmnTbaFSMhExRVQRRVJU9iUHjE7ez+fJ0MFipmUNhBV8YUd2SoIV9KkjQla9ltegttBdPLW4/qocL+UTfrMiHW4+P9M71shuyrqaHTcxsl7jegpsji8nh5ZwMvDfgTm0RTjSmjYdFCS6KoOIipdFunCgmNYTMv457MMY6U7iI6oMieDDhRm1VbIhuoOkbqtuK0Hpzb+eZcYZexUxt6UyUqK2cd0SdjtgrhOgijcgERUlJOCIl6CpgbP3blRI8XgMjNARAyKNDfeRBdFDBVUAXgQrqH4pxoJTu2NysY97LP4ac1io5q1InHFeGO24LnVKJuKOkSQ/yKir+rh7aCLG1dzypZQI2FnvTgccYOM3FeN0XWERXAUEFVQgQkUktdLpegm+Td3/Xli/L+S/mYNJIOF9G/wBeLKrZHFb0akG6W1WtQWSg3Dyg5e7V3fipE3O4/wCrktyzYA+ufas2LbZIlmnAT2kvuoN1wft95augilglX/tzP3qCu9O3LL/wV/i5v79BvmTADq14UGu91467Z6U9y0HzH/ncj/U/sT/CgynZG7I2NezpZGUjIycJkYkZSG+uQ81pbBNKLxJfjwoMqZ3/ALYHl35AJ7/cuwHcu5k7r1Q5pHetBjquqVVJWGxj9Zrtcl/Ggy3dHMvauR3HFZj5nHNxSyW5JISYDMoIwx8tFIGHZhPNaykGapr6rUAiicEoMG21lMRj8buPAz8xhJrr7uOeiPTCyAwXUaGR1mgozbTusOsFLEiJ7fbQa/h7gcjy2H3V6xppwDNtUSxCJIqp7valBuWVzJ22xuCROXNNZiJkMtms0DbjUkAZjzoDrTMd9dDRI44ZC2YsrYdKWP2WDT2S3N9dNdlRYrGMYc06IURXSYb0igrpWS485xVNS6nF4rwslkoMwnbpgZLB7bmt5uMweAhDEl4B5uSLzzqTnnyVpW2jaJHRMSIjdDiiotvy3DOE5rYTEbkl5yFn28k7JyG4c7AU2HtLH1uKfaiMPI40CdYbpNtmLdwTSn5rewLNld+7TLdeal4WarWBkbVKBjgdElMJJwAAY5fl4kB3b1fp4XvagsGS3FjJfLzDNtS8aeXx7LzT7TyzByQE5PccRGRC0ZRUDRV6y62vbjagzLmJzS2vuPK43JY6aP1TW6Jz+RIWyFtyC06y3EkiiinAo7YCqfq1AqqnGgsOH3lhZO8d1pmcpB8j5XIm9OYlBJSQ/FSS4427DKO0RC8AlcEMhFdViRR1WDWR5t3WXVuL1d106kG9vdeye2g60+1FDyW0shIcXVpyroXt8I8dfd+NB1vioAdWnD3UF1+gD4UFc6CEKpagxXN43rwJLUHz7yX2c8zokt9uHlsPIhA4aRnnHJTLptIS6CNsY7iASpxUUMkReGpfbQW0vtN5pitvrsN28rwtBD0nc0+/Yft5XhaB6TuaXfsP28rwtA9J3NPv2H7eV4Wgek7mn37D9vK8LQPSdzT79h+3leFoHpO5pd+w/byvC0D0nc0u/Yft5XhaB6TuaXfsP28rwtA9J3NLv2H7eV4Wgek7ml37D9vK8LQPSdzS79h+3leFoHpO5p9+w/byvC0E9r7Reazy2HIYVPxkS/CUHVn26cosxyv2g7h89LYmZSXOenvLEQ1YaQ222RATcQCP8rSGqqA8S02W2pQ6FhMoAIlqCtsnwoCpdKClejI4i3Sgtb+GBxVuNBSFt1pV/RQefLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8uM/JQPLjPyUDy4z8lA8utJ/koJ7WCbBU/LQXOPAFq1koK8B0pag90CggtBBf6qB0UDooHRQOigdFA6KB0UDooHRQOigdFA6KB0UDooI0EaBQf//Z" title="Toggle Table of Contents" alt="Toggle Table of Contents" />
  180. </a>
  181. </div>
  182. <div class="wy-grid-for-nav">
  183. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  184. <div class="wy-side-nav-search">
  185. <a href="../index.html" class="fa fa-home"> CodeIgniter</a>
  186. <div role="search">
  187. <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
  188. <input type="text" name="q" placeholder="Search docs" />
  189. <input type="hidden" name="check_keywords" value="yes" />
  190. <input type="hidden" name="area" value="default" />
  191. </form>
  192. </div>
  193. </div>
  194. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  195. <ul>
  196. <li class="toctree-l1"><a class="reference internal" href="../general/welcome.html">Welcome to CodeIgniter</a></li>
  197. </ul>
  198. <ul>
  199. <li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation Instructions</a><ul>
  200. <li class="toctree-l2"><a class="reference internal" href="../installation/downloads.html">Downloading CodeIgniter</a></li>
  201. <li class="toctree-l2"><a class="reference internal" href="../installation/index.html">Installation Instructions</a></li>
  202. <li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
  203. <li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
  204. </ul>
  205. </li>
  206. </ul>
  207. <ul>
  208. <li class="toctree-l1"><a class="reference internal" href="../overview/index.html">CodeIgniter Overview</a><ul>
  209. <li class="toctree-l2"><a class="reference internal" href="../overview/getting_started.html">Getting Started</a></li>
  210. <li class="toctree-l2"><a class="reference internal" href="../overview/at_a_glance.html">CodeIgniter at a Glance</a></li>
  211. <li class="toctree-l2"><a class="reference internal" href="../overview/features.html">Supported Features</a></li>
  212. <li class="toctree-l2"><a class="reference internal" href="../overview/appflow.html">Application Flow Chart</a></li>
  213. <li class="toctree-l2"><a class="reference internal" href="../overview/mvc.html">Model-View-Controller</a></li>
  214. <li class="toctree-l2"><a class="reference internal" href="../overview/goals.html">Architectural Goals</a></li>
  215. </ul>
  216. </li>
  217. </ul>
  218. <ul>
  219. <li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><ul>
  220. <li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
  221. <li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
  222. <li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
  223. <li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
  224. </ul>
  225. </li>
  226. </ul>
  227. <ul>
  228. <li class="toctree-l1"><a class="reference internal" href="../contributing/index.html">Contributing to CodeIgniter</a><ul>
  229. <li class="toctree-l2"><a class="reference internal" href="../documentation/index.html">Writing CodeIgniter Documentation</a></li>
  230. <li class="toctree-l2"><a class="reference internal" href="../DCO.html">Developer’s Certificate of Origin 1.1</a></li>
  231. </ul>
  232. </li>
  233. </ul>
  234. <ul>
  235. <li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
  236. <li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
  237. <li class="toctree-l2"><a class="reference internal" href="../general/controllers.html">Controllers</a></li>
  238. <li class="toctree-l2"><a class="reference internal" href="../general/reserved_names.html">Reserved Names</a></li>
  239. <li class="toctree-l2"><a class="reference internal" href="../general/views.html">Views</a></li>
  240. <li class="toctree-l2"><a class="reference internal" href="../general/models.html">Models</a></li>
  241. <li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helpers</a></li>
  242. <li class="toctree-l2"><a class="reference internal" href="../general/libraries.html">Using CodeIgniter Libraries</a></li>
  243. <li class="toctree-l2"><a class="reference internal" href="../general/creating_libraries.html">Creating Libraries</a></li>
  244. <li class="toctree-l2"><a class="reference internal" href="../general/drivers.html">Using CodeIgniter Drivers</a></li>
  245. <li class="toctree-l2"><a class="reference internal" href="../general/creating_drivers.html">Creating Drivers</a></li>
  246. <li class="toctree-l2"><a class="reference internal" href="../general/core_classes.html">Creating Core System Classes</a></li>
  247. <li class="toctree-l2"><a class="reference internal" href="../general/ancillary_classes.html">Creating Ancillary Classes</a></li>
  248. <li class="toctree-l2"><a class="reference internal" href="../general/hooks.html">Hooks - Extending the Framework Core</a></li>
  249. <li class="toctree-l2"><a class="reference internal" href="../general/autoloader.html">Auto-loading Resources</a></li>
  250. <li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Common Functions</a></li>
  251. <li class="toctree-l2"><a class="reference internal" href="../general/compatibility_functions.html">Compatibility Functions</a></li>
  252. <li class="toctree-l2"><a class="reference internal" href="../general/routing.html">URI Routing</a></li>
  253. <li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
  254. <li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Caching</a></li>
  255. <li class="toctree-l2"><a class="reference internal" href="../general/profiling.html">Profiling Your Application</a></li>
  256. <li class="toctree-l2"><a class="reference internal" href="../general/cli.html">Running via the CLI</a></li>
  257. <li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
  258. <li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
  259. <li class="toctree-l2"><a class="reference internal" href="../general/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
  260. <li class="toctree-l2"><a class="reference internal" href="../general/security.html">Security</a></li>
  261. <li class="toctree-l2"><a class="reference internal" href="../general/styleguide.html">PHP Style Guide</a></li>
  262. </ul>
  263. </li>
  264. </ul>
  265. <ul class="current">
  266. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Libraries</a><ul class="current">
  267. <li class="toctree-l2"><a class="reference internal" href="benchmark.html">Benchmarking Class</a></li>
  268. <li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li>
  269. <li class="toctree-l2"><a class="reference internal" href="calendar.html">Calendaring Class</a></li>
  270. <li class="toctree-l2"><a class="reference internal" href="cart.html">Shopping Cart Class</a></li>
  271. <li class="toctree-l2"><a class="reference internal" href="config.html">Config Class</a></li>
  272. <li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li>
  273. <li class="toctree-l2"><a class="reference internal" href="encrypt.html">Encrypt Class</a></li>
  274. <li class="toctree-l2"><a class="reference internal" href="encryption.html">Encryption Library</a></li>
  275. <li class="toctree-l2 current"><a class="current reference internal" href="#">File Uploading Class</a></li>
  276. <li class="toctree-l2"><a class="reference internal" href="form_validation.html">Form Validation</a></li>
  277. <li class="toctree-l2"><a class="reference internal" href="ftp.html">FTP Class</a></li>
  278. <li class="toctree-l2"><a class="reference internal" href="image_lib.html">Image Manipulation Class</a></li>
  279. <li class="toctree-l2"><a class="reference internal" href="input.html">Input Class</a></li>
  280. <li class="toctree-l2"><a class="reference internal" href="javascript.html">Javascript Class</a></li>
  281. <li class="toctree-l2"><a class="reference internal" href="language.html">Language Class</a></li>
  282. <li class="toctree-l2"><a class="reference internal" href="loader.html">Loader Class</a></li>
  283. <li class="toctree-l2"><a class="reference internal" href="migration.html">Migrations Class</a></li>
  284. <li class="toctree-l2"><a class="reference internal" href="output.html">Output Class</a></li>
  285. <li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination Class</a></li>
  286. <li class="toctree-l2"><a class="reference internal" href="parser.html">Template Parser Class</a></li>
  287. <li class="toctree-l2"><a class="reference internal" href="security.html">Security Class</a></li>
  288. <li class="toctree-l2"><a class="reference internal" href="sessions.html">Session Library</a></li>
  289. <li class="toctree-l2"><a class="reference internal" href="table.html">HTML Table Class</a></li>
  290. <li class="toctree-l2"><a class="reference internal" href="trackback.html">Trackback Class</a></li>
  291. <li class="toctree-l2"><a class="reference internal" href="typography.html">Typography Class</a></li>
  292. <li class="toctree-l2"><a class="reference internal" href="unit_testing.html">Unit Testing Class</a></li>
  293. <li class="toctree-l2"><a class="reference internal" href="uri.html">URI Class</a></li>
  294. <li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li>
  295. <li class="toctree-l2"><a class="reference internal" href="xmlrpc.html">XML-RPC and XML-RPC Server Classes</a></li>
  296. <li class="toctree-l2"><a class="reference internal" href="zip.html">Zip Encoding Class</a></li>
  297. </ul>
  298. </li>
  299. </ul>
  300. <ul>
  301. <li class="toctree-l1"><a class="reference internal" href="../database/index.html">Database Reference</a><ul>
  302. <li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
  303. <li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
  304. <li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
  305. <li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
  306. <li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
  307. <li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
  308. <li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
  309. <li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
  310. <li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
  311. <li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
  312. <li class="toctree-l2"><a class="reference internal" href="../database/caching.html">Query Caching</a></li>
  313. <li class="toctree-l2"><a class="reference internal" href="../database/forge.html">Database Manipulation with Database Forge</a></li>
  314. <li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities Class</a></li>
  315. <li class="toctree-l2"><a class="reference internal" href="../database/db_driver_reference.html">Database Driver Reference</a></li>
  316. </ul>
  317. </li>
  318. </ul>
  319. <ul>
  320. <li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
  321. <li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
  322. <li class="toctree-l2"><a class="reference internal" href="../helpers/captcha_helper.html">CAPTCHA Helper</a></li>
  323. <li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
  324. <li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
  325. <li class="toctree-l2"><a class="reference internal" href="../helpers/directory_helper.html">Directory Helper</a></li>
  326. <li class="toctree-l2"><a class="reference internal" href="../helpers/download_helper.html">Download Helper</a></li>
  327. <li class="toctree-l2"><a class="reference internal" href="../helpers/email_helper.html">Email Helper</a></li>
  328. <li class="toctree-l2"><a class="reference internal" href="../helpers/file_helper.html">File Helper</a></li>
  329. <li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
  330. <li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
  331. <li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
  332. <li class="toctree-l2"><a class="reference internal" href="../helpers/language_helper.html">Language Helper</a></li>
  333. <li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
  334. <li class="toctree-l2"><a class="reference internal" href="../helpers/path_helper.html">Path Helper</a></li>
  335. <li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
  336. <li class="toctree-l2"><a class="reference internal" href="../helpers/smiley_helper.html">Smiley Helper</a></li>
  337. <li class="toctree-l2"><a class="reference internal" href="../helpers/string_helper.html">String Helper</a></li>
  338. <li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
  339. <li class="toctree-l2"><a class="reference internal" href="../helpers/typography_helper.html">Typography Helper</a></li>
  340. <li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
  341. <li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
  342. </ul>
  343. </li>
  344. </ul>
  345. </div>
  346. &nbsp;
  347. </nav>
  348. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  349. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  350. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  351. <a href="../index.html">CodeIgniter</a>
  352. </nav>
  353. <div class="wy-nav-content">
  354. <div class="rst-content">
  355. <div role="navigation" aria-label="breadcrumbs navigation">
  356. <ul class="wy-breadcrumbs">
  357. <li><a href="../index.html">Docs</a> &raquo;</li>
  358. <li><a href="index.html">Libraries</a> &raquo;</li>
  359. <li>File Uploading Class</li>
  360. <li class="wy-breadcrumbs-aside">
  361. </li>
  362. <div style="float:right;margin-left:5px;" id="closeMe">
  363. <img title="Classic Layout" alt="classic layout" src="data:image/gif;base64,R0lGODlhFAAUAJEAAAAAADMzM////wAAACH5BAUUAAIALAAAAAAUABQAAAImlI+py+0PU5gRBRDM3DxbWoXis42X13USOLauUIqnlsaH/eY6UwAAOw==" />
  364. </div>
  365. </ul>
  366. <hr/>
  367. </div>
  368. <div role="main" class="document">
  369. <div class="section" id="file-uploading-class">
  370. <h1>File Uploading Class<a class="headerlink" href="#file-uploading-class" title="Permalink to this headline">¶</a></h1>
  371. <p>CodeIgniter’s File Uploading Class permits files to be uploaded. You can
  372. set various preferences, restricting the type and size of the files.</p>
  373. <div class="contents local topic" id="contents">
  374. <ul class="simple">
  375. <li><a class="reference internal" href="#the-process" id="id1">The Process</a><ul>
  376. <li><a class="reference internal" href="#creating-the-upload-form" id="id2">Creating the Upload Form</a></li>
  377. <li><a class="reference internal" href="#the-success-page" id="id3">The Success Page</a></li>
  378. <li><a class="reference internal" href="#the-controller" id="id4">The Controller</a></li>
  379. <li><a class="reference internal" href="#the-upload-directory" id="id5">The Upload Directory</a></li>
  380. <li><a class="reference internal" href="#try-it" id="id6">Try it!</a></li>
  381. </ul>
  382. </li>
  383. <li><a class="reference internal" href="#reference-guide" id="id7">Reference Guide</a><ul>
  384. <li><a class="reference internal" href="#initializing-the-upload-class" id="id8">Initializing the Upload Class</a></li>
  385. <li><a class="reference internal" href="#setting-preferences" id="id9">Setting Preferences</a></li>
  386. <li><a class="reference internal" href="#preferences" id="id10">Preferences</a></li>
  387. <li><a class="reference internal" href="#setting-preferences-in-a-config-file" id="id11">Setting preferences in a config file</a></li>
  388. </ul>
  389. </li>
  390. <li><a class="reference internal" href="#class-reference" id="id12">Class Reference</a></li>
  391. </ul>
  392. </div>
  393. <div class="custom-index container"></div><div class="section" id="the-process">
  394. <h2><a class="toc-backref" href="#id1">The Process</a><a class="headerlink" href="#the-process" title="Permalink to this headline">¶</a></h2>
  395. <p>Uploading a file involves the following general process:</p>
  396. <ul class="simple">
  397. <li>An upload form is displayed, allowing a user to select a file and
  398. upload it.</li>
  399. <li>When the form is submitted, the file is uploaded to the destination
  400. you specify.</li>
  401. <li>Along the way, the file is validated to make sure it is allowed to be
  402. uploaded based on the preferences you set.</li>
  403. <li>Once uploaded, the user will be shown a success message.</li>
  404. </ul>
  405. <p>To demonstrate this process here is brief tutorial. Afterward you’ll
  406. find reference information.</p>
  407. <div class="section" id="creating-the-upload-form">
  408. <h3><a class="toc-backref" href="#id2">Creating the Upload Form</a><a class="headerlink" href="#creating-the-upload-form" title="Permalink to this headline">¶</a></h3>
  409. <p>Using a text editor, create a form called upload_form.php. In it, place
  410. this code and save it to your <strong>application/views/</strong> directory:</p>
  411. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="nx">html</span><span class="o">&gt;</span>
  412. <span class="o">&lt;</span><span class="nx">head</span><span class="o">&gt;</span>
  413. <span class="o">&lt;</span><span class="nx">title</span><span class="o">&gt;</span><span class="nx">Upload</span> <span class="nx">Form</span><span class="o">&lt;/</span><span class="nx">title</span><span class="o">&gt;</span>
  414. <span class="o">&lt;/</span><span class="nx">head</span><span class="o">&gt;</span>
  415. <span class="o">&lt;</span><span class="nx">body</span><span class="o">&gt;</span>
  416. <span class="o">&lt;?</span><span class="nx">php</span> <span class="k">echo</span> <span class="nv">$error</span><span class="p">;</span><span class="cp">?&gt;</span>
  417. <span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">form_open_multipart</span><span class="p">(</span><span class="s1">&#39;upload/do_upload&#39;</span><span class="p">);</span><span class="cp">?&gt;</span>
  418. <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;file&quot;</span> <span class="na">name</span><span class="o">=</span><span class="s">&quot;userfile&quot;</span> <span class="na">size</span><span class="o">=</span><span class="s">&quot;20&quot;</span> <span class="p">/&gt;</span>
  419. <span class="p">&lt;</span><span class="nt">br</span> <span class="p">/&gt;&lt;</span><span class="nt">br</span> <span class="p">/&gt;</span>
  420. <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;submit&quot;</span> <span class="na">value</span><span class="o">=</span><span class="s">&quot;upload&quot;</span> <span class="p">/&gt;</span>
  421. <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
  422. <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
  423. <span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
  424. </pre></div>
  425. </div>
  426. <p>You’ll notice we are using a form helper to create the opening form tag.
  427. File uploads require a multipart form, so the helper creates the proper
  428. syntax for you. You’ll also notice we have an $error variable. This is
  429. so we can show error messages in the event the user does something
  430. wrong.</p>
  431. </div>
  432. <div class="section" id="the-success-page">
  433. <h3><a class="toc-backref" href="#id3">The Success Page</a><a class="headerlink" href="#the-success-page" title="Permalink to this headline">¶</a></h3>
  434. <p>Using a text editor, create a form called upload_success.php. In it,
  435. place this code and save it to your <strong>application/views/</strong> directory:</p>
  436. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="nx">html</span><span class="o">&gt;</span>
  437. <span class="o">&lt;</span><span class="nx">head</span><span class="o">&gt;</span>
  438. <span class="o">&lt;</span><span class="nx">title</span><span class="o">&gt;</span><span class="nx">Upload</span> <span class="nx">Form</span><span class="o">&lt;/</span><span class="nx">title</span><span class="o">&gt;</span>
  439. <span class="o">&lt;/</span><span class="nx">head</span><span class="o">&gt;</span>
  440. <span class="o">&lt;</span><span class="nx">body</span><span class="o">&gt;</span>
  441. <span class="o">&lt;</span><span class="nx">h3</span><span class="o">&gt;</span><span class="nx">Your</span> <span class="nb">file</span> <span class="nx">was</span> <span class="nx">successfully</span> <span class="nx">uploaded</span><span class="o">!&lt;/</span><span class="nx">h3</span><span class="o">&gt;</span>
  442. <span class="o">&lt;</span><span class="nx">ul</span><span class="o">&gt;</span>
  443. <span class="o">&lt;?</span><span class="nx">php</span> <span class="k">foreach</span> <span class="p">(</span><span class="nv">$upload_data</span> <span class="k">as</span> <span class="nv">$item</span> <span class="o">=&gt;</span> <span class="nv">$value</span><span class="p">)</span><span class="o">:</span><span class="cp">?&gt;</span>
  444. <span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$item</span><span class="p">;</span><span class="cp">?&gt;</span>: <span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$value</span><span class="p">;</span><span class="cp">?&gt;</span><span class="p">&lt;/</span><span class="nt">li</span><span class="p">&gt;</span>
  445. <span class="cp">&lt;?php</span> <span class="k">endforeach</span><span class="p">;</span> <span class="cp">?&gt;</span>
  446. <span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
  447. <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">anchor</span><span class="p">(</span><span class="s1">&#39;upload&#39;</span><span class="p">,</span> <span class="s1">&#39;Upload Another File!&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
  448. <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
  449. <span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
  450. </pre></div>
  451. </div>
  452. </div>
  453. <div class="section" id="the-controller">
  454. <h3><a class="toc-backref" href="#id4">The Controller</a><a class="headerlink" href="#the-controller" title="Permalink to this headline">¶</a></h3>
  455. <p>Using a text editor, create a controller called Upload.php. In it, place
  456. this code and save it to your <strong>application/controllers/</strong> directory:</p>
  457. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o">&lt;?</span><span class="nx">php</span>
  458. <span class="k">class</span> <span class="nc">Upload</span> <span class="k">extends</span> <span class="nx">CI_Controller</span> <span class="p">{</span>
  459. <span class="k">public</span> <span class="k">function</span> <span class="nf">__construct</span><span class="p">()</span>
  460. <span class="p">{</span>
  461. <span class="k">parent</span><span class="o">::</span><span class="na">__construct</span><span class="p">();</span>
  462. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">helper</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">&#39;form&#39;</span><span class="p">,</span> <span class="s1">&#39;url&#39;</span><span class="p">));</span>
  463. <span class="p">}</span>
  464. <span class="k">public</span> <span class="k">function</span> <span class="nf">index</span><span class="p">()</span>
  465. <span class="p">{</span>
  466. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">view</span><span class="p">(</span><span class="s1">&#39;upload_form&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;error&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39; &#39;</span> <span class="p">));</span>
  467. <span class="p">}</span>
  468. <span class="k">public</span> <span class="k">function</span> <span class="nf">do_upload</span><span class="p">()</span>
  469. <span class="p">{</span>
  470. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;upload_path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;./uploads/&#39;</span><span class="p">;</span>
  471. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;allowed_types&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;gif|jpg|png&#39;</span><span class="p">;</span>
  472. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;max_size&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span>
  473. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;max_width&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1024</span><span class="p">;</span>
  474. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;max_height&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">768</span><span class="p">;</span>
  475. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">library</span><span class="p">(</span><span class="s1">&#39;upload&#39;</span><span class="p">,</span> <span class="nv">$config</span><span class="p">);</span>
  476. <span class="k">if</span> <span class="p">(</span> <span class="o">!</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">upload</span><span class="o">-&gt;</span><span class="na">do_upload</span><span class="p">(</span><span class="s1">&#39;userfile&#39;</span><span class="p">))</span>
  477. <span class="p">{</span>
  478. <span class="nv">$error</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;error&#39;</span> <span class="o">=&gt;</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">upload</span><span class="o">-&gt;</span><span class="na">display_errors</span><span class="p">());</span>
  479. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">view</span><span class="p">(</span><span class="s1">&#39;upload_form&#39;</span><span class="p">,</span> <span class="nv">$error</span><span class="p">);</span>
  480. <span class="p">}</span>
  481. <span class="k">else</span>
  482. <span class="p">{</span>
  483. <span class="nv">$data</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;upload_data&#39;</span> <span class="o">=&gt;</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">upload</span><span class="o">-&gt;</span><span class="na">data</span><span class="p">());</span>
  484. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">view</span><span class="p">(</span><span class="s1">&#39;upload_success&#39;</span><span class="p">,</span> <span class="nv">$data</span><span class="p">);</span>
  485. <span class="p">}</span>
  486. <span class="p">}</span>
  487. <span class="p">}</span>
  488. <span class="cp">?&gt;</span>
  489. </pre></div>
  490. </div>
  491. </div>
  492. <div class="section" id="the-upload-directory">
  493. <h3><a class="toc-backref" href="#id5">The Upload Directory</a><a class="headerlink" href="#the-upload-directory" title="Permalink to this headline">¶</a></h3>
  494. <p>You’ll need a destination directory for your uploaded images. Create a
  495. directory at the root of your CodeIgniter installation called uploads
  496. and set its file permissions to 777.</p>
  497. </div>
  498. <div class="section" id="try-it">
  499. <h3><a class="toc-backref" href="#id6">Try it!</a><a class="headerlink" href="#try-it" title="Permalink to this headline">¶</a></h3>
  500. <p>To try your form, visit your site using a URL similar to this one:</p>
  501. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nx">example</span><span class="o">.</span><span class="nx">com</span><span class="o">/</span><span class="nx">index</span><span class="o">.</span><span class="nx">php</span><span class="o">/</span><span class="nx">upload</span><span class="o">/</span>
  502. </pre></div>
  503. </div>
  504. <p>You should see an upload form. Try uploading an image file (either a
  505. jpg, gif, or png). If the path in your controller is correct it should
  506. work.</p>
  507. </div>
  508. </div>
  509. <div class="section" id="reference-guide">
  510. <h2><a class="toc-backref" href="#id7">Reference Guide</a><a class="headerlink" href="#reference-guide" title="Permalink to this headline">¶</a></h2>
  511. <div class="section" id="initializing-the-upload-class">
  512. <h3><a class="toc-backref" href="#id8">Initializing the Upload Class</a><a class="headerlink" href="#initializing-the-upload-class" title="Permalink to this headline">¶</a></h3>
  513. <p>Like most other classes in CodeIgniter, the Upload class is initialized
  514. in your controller using the <code class="docutils literal"><span class="pre">$this-&gt;load-&gt;library()</span></code> method:</p>
  515. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">library</span><span class="p">(</span><span class="s1">&#39;upload&#39;</span><span class="p">);</span>
  516. </pre></div>
  517. </div>
  518. <p>Once the Upload class is loaded, the object will be available using:
  519. $this-&gt;upload</p>
  520. </div>
  521. <div class="section" id="setting-preferences">
  522. <h3><a class="toc-backref" href="#id9">Setting Preferences</a><a class="headerlink" href="#setting-preferences" title="Permalink to this headline">¶</a></h3>
  523. <p>Similar to other libraries, you’ll control what is allowed to be upload
  524. based on your preferences. In the controller you built above you set the
  525. following preferences:</p>
  526. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;upload_path&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;./uploads/&#39;</span><span class="p">;</span>
  527. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;allowed_types&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;gif|jpg|png&#39;</span><span class="p">;</span>
  528. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;max_size&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;100&#39;</span><span class="p">;</span>
  529. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;max_width&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;1024&#39;</span><span class="p">;</span>
  530. <span class="nv">$config</span><span class="p">[</span><span class="s1">&#39;max_height&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;768&#39;</span><span class="p">;</span>
  531. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">load</span><span class="o">-&gt;</span><span class="na">library</span><span class="p">(</span><span class="s1">&#39;upload&#39;</span><span class="p">,</span> <span class="nv">$config</span><span class="p">);</span>
  532. <span class="c1">// Alternately you can set preferences by calling the ``initialize()`` method. Useful if you auto-load the class:</span>
  533. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">upload</span><span class="o">-&gt;</span><span class="na">initialize</span><span class="p">(</span><span class="nv">$config</span><span class="p">);</span>
  534. </pre></div>
  535. </div>
  536. <p>The above preferences should be fairly self-explanatory. Below is a
  537. table describing all available preferences.</p>
  538. </div>
  539. <div class="section" id="preferences">
  540. <h3><a class="toc-backref" href="#id10">Preferences</a><a class="headerlink" href="#preferences" title="Permalink to this headline">¶</a></h3>
  541. <p>The following preferences are available. The default value indicates
  542. what will be used if you do not specify that preference.</p>
  543. <table border="1" class="docutils">
  544. <colgroup>
  545. <col width="20%" />
  546. <col width="12%" />
  547. <col width="16%" />
  548. <col width="51%" />
  549. </colgroup>
  550. <thead valign="bottom">
  551. <tr class="row-odd"><th class="head">Preference</th>
  552. <th class="head">Default Value</th>
  553. <th class="head">Options</th>
  554. <th class="head">Description</th>
  555. </tr>
  556. </thead>
  557. <tbody valign="top">
  558. <tr class="row-even"><td><strong>upload_path</strong></td>
  559. <td>None</td>
  560. <td>None</td>
  561. <td>The path to the directory where the upload should be placed. The
  562. directory must be writable and the path can be absolute or relative.</td>
  563. </tr>
  564. <tr class="row-odd"><td><strong>allowed_types</strong></td>
  565. <td>None</td>
  566. <td>None</td>
  567. <td>The mime types corresponding to the types of files you allow to be
  568. uploaded. Usually the file extension can be used as the mime type.
  569. Can be either an array or a pipe-separated string.</td>
  570. </tr>
  571. <tr class="row-even"><td><strong>file_name</strong></td>
  572. <td>None</td>
  573. <td>Desired file name</td>
  574. <td>If set CodeIgniter will rename the uploaded file to this name. The
  575. extension provided in the file name must also be an allowed file type.
  576. If no extension is provided in the original file_name will be used.</td>
  577. </tr>
  578. <tr class="row-odd"><td><strong>file_ext_tolower</strong></td>
  579. <td>FALSE</td>
  580. <td>TRUE/FALSE (boolean)</td>
  581. <td>If set to TRUE, the file extension will be forced to lower case</td>
  582. </tr>
  583. <tr class="row-even"><td><strong>overwrite</strong></td>
  584. <td>FALSE</td>
  585. <td>TRUE/FALSE (boolean)</td>
  586. <td>If set to true, if a file with the same name as the one you are
  587. uploading exists, it will be overwritten. If set to false, a number will
  588. be appended to the filename if another with the same name exists.</td>
  589. </tr>
  590. <tr class="row-odd"><td><strong>max_size</strong></td>
  591. <td>0</td>
  592. <td>None</td>
  593. <td>The maximum size (in kilobytes) that the file can be. Set to zero for no
  594. limit. Note: Most PHP installations have their own limit, as specified
  595. in the php.ini file. Usually 2 MB (or 2048 KB) by default.</td>
  596. </tr>
  597. <tr class="row-even"><td><strong>max_width</strong></td>
  598. <td>0</td>
  599. <td>None</td>
  600. <td>The maximum width (in pixels) that the image can be. Set to zero for no
  601. limit.</td>
  602. </tr>
  603. <tr class="row-odd"><td><strong>max_height</strong></td>
  604. <td>0</td>
  605. <td>None</td>
  606. <td>The maximum height (in pixels) that the image can be. Set to zero for no
  607. limit.</td>
  608. </tr>
  609. <tr class="row-even"><td><strong>min_width</strong></td>
  610. <td>0</td>
  611. <td>None</td>
  612. <td>The minimum width (in pixels) that the image can be. Set to zero for no
  613. limit.</td>
  614. </tr>
  615. <tr class="row-odd"><td><strong>min_height</strong></td>
  616. <td>0</td>
  617. <td>None</td>
  618. <td>The minimum height (in pixels) that the image can be. Set to zero for no
  619. limit.</td>
  620. </tr>
  621. <tr class="row-even"><td><strong>max_filename</strong></td>
  622. <td>0</td>
  623. <td>None</td>
  624. <td>The maximum length that a file name can be. Set to zero for no limit.</td>
  625. </tr>
  626. <tr class="row-odd"><td><strong>max_filename_increment</strong></td>
  627. <td>100</td>
  628. <td>None</td>
  629. <td>When overwrite is set to FALSE, use this to set the maximum filename
  630. increment for CodeIgniter to append to the filename.</td>
  631. </tr>
  632. <tr class="row-even"><td><strong>encrypt_name</strong></td>
  633. <td>FALSE</td>
  634. <td>TRUE/FALSE (boolean)</td>
  635. <td>If set to TRUE the file name will be converted to a random encrypted
  636. string. This can be useful if you would like the file saved with a name
  637. that can not be discerned by the person uploading it.</td>
  638. </tr>
  639. <tr class="row-odd"><td><strong>remove_spaces</strong></td>
  640. <td>TRUE</td>
  641. <td>TRUE/FALSE (boolean)</td>
  642. <td>If set to TRUE, any spaces in the file name will be converted to
  643. underscores. This is recommended.</td>
  644. </tr>
  645. <tr class="row-even"><td><strong>detect_mime</strong></td>
  646. <td>TRUE</td>
  647. <td>TRUE/FALSE (boolean)</td>
  648. <td>If set to TRUE, a server side detection of the file type will be
  649. performed to avoid code injection attacks. DO NOT disable this option
  650. unless you have no other option as that would cause a security risk.</td>
  651. </tr>
  652. <tr class="row-odd"><td><strong>mod_mime_fix</strong></td>
  653. <td>TRUE</td>
  654. <td>TRUE/FALSE (boolean)</td>
  655. <td>If set to TRUE, multiple filename extensions will be suffixed with an
  656. underscore in order to avoid triggering <a class="reference external" href="http://httpd.apache.org/docs/2.0/mod/mod_mime.html#multipleext">Apache mod_mime</a>.
  657. DO NOT turn off this option if your upload directory is public, as this
  658. is a security risk.</td>
  659. </tr>
  660. </tbody>
  661. </table>
  662. </div>
  663. <div class="section" id="setting-preferences-in-a-config-file">
  664. <h3><a class="toc-backref" href="#id11">Setting preferences in a config file</a><a class="headerlink" href="#setting-preferences-in-a-config-file" title="Permalink to this headline">¶</a></h3>
  665. <p>If you prefer not to set preferences using the above method, you can
  666. instead put them into a config file. Simply create a new file called the
  667. upload.php, add the $config array in that file. Then save the file in:
  668. <strong>config/upload.php</strong> and it will be used automatically. You will NOT
  669. need to use the <code class="docutils literal"><span class="pre">$this-&gt;upload-&gt;initialize()</span></code> method if you save your
  670. preferences in a config file.</p>
  671. </div>
  672. </div>
  673. <div class="section" id="class-reference">
  674. <h2><a class="toc-backref" href="#id12">Class Reference</a><a class="headerlink" href="#class-reference" title="Permalink to this headline">¶</a></h2>
  675. <dl class="class">
  676. <dt id="CI_Upload">
  677. <em class="property">class </em><code class="descname">CI_Upload</code><a class="headerlink" href="#CI_Upload" title="Permalink to this definition">¶</a></dt>
  678. <dd><dl class="method">
  679. <dt id="CI_Upload::initialize">
  680. <code class="descname">initialize</code><span class="sig-paren">(</span><span class="optional">[</span><em>array $config = array()</em><span class="optional">[</span>, <em>$reset = TRUE</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Upload::initialize" title="Permalink to this definition">¶</a></dt>
  681. <dd><table class="docutils field-list" frame="void" rules="none">
  682. <col class="field-name" />
  683. <col class="field-body" />
  684. <tbody valign="top">
  685. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  686. <li><strong>$config</strong> (<em>array</em>) – Preferences</li>
  687. <li><strong>$reset</strong> (<em>bool</em>) – Whether to reset preferences (that are not provided in $config) to their defaults</li>
  688. </ul>
  689. </td>
  690. </tr>
  691. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">CI_Upload instance (method chaining)</p>
  692. </td>
  693. </tr>
  694. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">CI_Upload</p>
  695. </td>
  696. </tr>
  697. </tbody>
  698. </table>
  699. </dd></dl>
  700. <dl class="method">
  701. <dt id="CI_Upload::do_upload">
  702. <code class="descname">do_upload</code><span class="sig-paren">(</span><span class="optional">[</span><em>$field = 'userfile'</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Upload::do_upload" title="Permalink to this definition">¶</a></dt>
  703. <dd><table class="docutils field-list" frame="void" rules="none">
  704. <col class="field-name" />
  705. <col class="field-body" />
  706. <tbody valign="top">
  707. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  708. <li><strong>$field</strong> (<em>string</em>) – Name of the form field</li>
  709. </ul>
  710. </td>
  711. </tr>
  712. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">TRUE on success, FALSE on failure</p>
  713. </td>
  714. </tr>
  715. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">bool</p>
  716. </td>
  717. </tr>
  718. </tbody>
  719. </table>
  720. <p>Performs the upload based on the preferences you’ve set.</p>
  721. <div class="admonition note">
  722. <p class="first admonition-title">Note</p>
  723. <p class="last">By default the upload routine expects the file to come from
  724. a form field called userfile, and the form must be of type
  725. “multipart”.</p>
  726. </div>
  727. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="nx">form</span> <span class="nx">method</span><span class="o">=</span><span class="s2">&quot;post&quot;</span> <span class="nx">action</span><span class="o">=</span><span class="s2">&quot;some_action&quot;</span> <span class="nx">enctype</span><span class="o">=</span><span class="s2">&quot;multipart/form-data&quot;</span> <span class="o">/&gt;</span>
  728. </pre></div>
  729. </div>
  730. <p>If you would like to set your own field name simply pass its value to
  731. the <code class="docutils literal"><span class="pre">do_upload()</span></code> method:</p>
  732. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$field_name</span> <span class="o">=</span> <span class="s2">&quot;some_field_name&quot;</span><span class="p">;</span>
  733. <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">upload</span><span class="o">-&gt;</span><span class="na">do_upload</span><span class="p">(</span><span class="nv">$field_name</span><span class="p">);</span>
  734. </pre></div>
  735. </div>
  736. </dd></dl>
  737. <dl class="method">
  738. <dt id="CI_Upload::display_errors">
  739. <code class="descname">display_errors</code><span class="sig-paren">(</span><span class="optional">[</span><em>$open = '&lt;p&gt;'</em><span class="optional">[</span>, <em>$close = '&lt;/p&gt;'</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Upload::display_errors" title="Permalink to this definition">¶</a></dt>
  740. <dd><table class="docutils field-list" frame="void" rules="none">
  741. <col class="field-name" />
  742. <col class="field-body" />
  743. <tbody valign="top">
  744. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  745. <li><strong>$open</strong> (<em>string</em>) – Opening markup</li>
  746. <li><strong>$close</strong> (<em>string</em>) – Closing markup</li>
  747. </ul>
  748. </td>
  749. </tr>
  750. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Formatted error message(s)</p>
  751. </td>
  752. </tr>
  753. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
  754. </td>
  755. </tr>
  756. </tbody>
  757. </table>
  758. <p>Retrieves any error messages if the <code class="docutils literal"><span class="pre">do_upload()</span></code> method returned
  759. false. The method does not echo automatically, it returns the data so
  760. you can assign it however you need.</p>
  761. <p><strong>Formatting Errors</strong></p>
  762. <blockquote>
  763. <div><p>By default the above method wraps any errors within &lt;p&gt; tags. You can
  764. set your own delimiters like this:</p>
  765. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">upload</span><span class="o">-&gt;</span><span class="na">display_errors</span><span class="p">(</span><span class="s1">&#39;&lt;p&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;/p&gt;&#39;</span><span class="p">);</span>
  766. </pre></div>
  767. </div>
  768. </div></blockquote>
  769. </dd></dl>
  770. <dl class="method">
  771. <dt id="CI_Upload::data">
  772. <code class="descname">data</code><span class="sig-paren">(</span><span class="optional">[</span><em>$index = NULL</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#CI_Upload::data" title="Permalink to this definition">¶</a></dt>
  773. <dd><table class="docutils field-list" frame="void" rules="none">
  774. <col class="field-name" />
  775. <col class="field-body" />
  776. <tbody valign="top">
  777. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  778. <li><strong>$data</strong> (<em>string</em>) – Element to return instead of the full array</li>
  779. </ul>
  780. </td>
  781. </tr>
  782. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">Information about the uploaded file</p>
  783. </td>
  784. </tr>
  785. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">mixed</p>
  786. </td>
  787. </tr>
  788. </tbody>
  789. </table>
  790. <p>This is a helper method that returns an array containing all of the
  791. data related to the file you uploaded. Here is the array prototype:</p>
  792. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="k">Array</span>
  793. <span class="p">(</span>
  794. <span class="p">[</span><span class="nx">file_name</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="nx">mypic</span><span class="o">.</span><span class="nx">jpg</span>
  795. <span class="p">[</span><span class="nx">file_type</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="nx">image</span><span class="o">/</span><span class="nx">jpeg</span>
  796. <span class="p">[</span><span class="nx">file_path</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="o">/</span><span class="nx">path</span><span class="o">/</span><span class="nx">to</span><span class="o">/</span><span class="nx">your</span><span class="o">/</span><span class="nx">upload</span><span class="o">/</span>
  797. <span class="p">[</span><span class="nx">full_path</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="o">/</span><span class="nx">path</span><span class="o">/</span><span class="nx">to</span><span class="o">/</span><span class="nx">your</span><span class="o">/</span><span class="nx">upload</span><span class="o">/</span><span class="nx">jpg</span><span class="o">.</span><span class="nx">jpg</span>
  798. <span class="p">[</span><span class="nx">raw_name</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="nx">mypic</span>
  799. <span class="p">[</span><span class="nx">orig_name</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="nx">mypic</span><span class="o">.</span><span class="nx">jpg</span>
  800. <span class="p">[</span><span class="nx">client_name</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="nx">mypic</span><span class="o">.</span><span class="nx">jpg</span>
  801. <span class="p">[</span><span class="nx">file_ext</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="o">.</span><span class="nx">jpg</span>
  802. <span class="p">[</span><span class="nx">file_size</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="mf">22.2</span>
  803. <span class="p">[</span><span class="nx">is_image</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="mi">1</span>
  804. <span class="p">[</span><span class="nx">image_width</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="mi">800</span>
  805. <span class="p">[</span><span class="nx">image_height</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="mi">600</span>
  806. <span class="p">[</span><span class="nx">image_type</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="nx">jpeg</span>
  807. <span class="p">[</span><span class="nx">image_size_str</span><span class="p">]</span> <span class="o">=&gt;</span> <span class="nx">width</span><span class="o">=</span><span class="s2">&quot;800&quot;</span> <span class="nx">height</span><span class="o">=</span><span class="s2">&quot;200&quot;</span>
  808. <span class="p">)</span>
  809. </pre></div>
  810. </div>
  811. <p>To return one element from the array:</p>
  812. <div class="highlight-ci"><div class="highlight"><pre><span></span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">upload</span><span class="o">-&gt;</span><span class="na">data</span><span class="p">(</span><span class="s1">&#39;file_name&#39;</span><span class="p">);</span> <span class="c1">// Returns: mypic.jpg</span>
  813. </pre></div>
  814. </div>
  815. <p>Here’s a table explaining the above-displayed array items:</p>
  816. <table border="1" class="docutils">
  817. <colgroup>
  818. <col width="14%" />
  819. <col width="86%" />
  820. </colgroup>
  821. <thead valign="bottom">
  822. <tr class="row-odd"><th class="head">Item</th>
  823. <th class="head">Description</th>
  824. </tr>
  825. </thead>
  826. <tbody valign="top">
  827. <tr class="row-even"><td>file_name</td>
  828. <td>Name of the file that was uploaded, including the filename extension</td>
  829. </tr>
  830. <tr class="row-odd"><td>file_type</td>
  831. <td>File MIME type identifier</td>
  832. </tr>
  833. <tr class="row-even"><td>file_path</td>
  834. <td>Absolute server path to the file</td>
  835. </tr>
  836. <tr class="row-odd"><td>full_path</td>
  837. <td>Absolute server path, including the file name</td>
  838. </tr>
  839. <tr class="row-even"><td>raw_name</td>
  840. <td>File name, without the extension</td>
  841. </tr>
  842. <tr class="row-odd"><td>orig_name</td>
  843. <td>Original file name. This is only useful if you use the encrypted name option.</td>
  844. </tr>
  845. <tr class="row-even"><td>client_name</td>
  846. <td>File name supplied by the client user agent, but possibly sanitized</td>
  847. </tr>
  848. <tr class="row-odd"><td>file_ext</td>
  849. <td>Filename extension, period included</td>
  850. </tr>
  851. <tr class="row-even"><td>file_size</td>
  852. <td>File size in kilobytes</td>
  853. </tr>
  854. <tr class="row-odd"><td>is_image</td>
  855. <td>Whether the file is an image or not. 1 = image. 0 = not.</td>
  856. </tr>
  857. <tr class="row-even"><td>image_width</td>
  858. <td>Image width</td>
  859. </tr>
  860. <tr class="row-odd"><td>image_height</td>
  861. <td>Image height</td>
  862. </tr>
  863. <tr class="row-even"><td>image_type</td>
  864. <td>Image type (usually the file name extension without the period)</td>
  865. </tr>
  866. <tr class="row-odd"><td>image_size_str</td>
  867. <td>A string containing the width and height (useful to put into an image tag)</td>
  868. </tr>
  869. </tbody>
  870. </table>
  871. </dd></dl>
  872. </dd></dl>
  873. </div>
  874. </div>
  875. </div>
  876. <footer>
  877. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  878. <a href="form_validation.html" class="btn btn-neutral float-right" title="Form Validation">Next <span class="fa fa-arrow-circle-right"></span></a>
  879. <a href="encryption.html" class="btn btn-neutral" title="Encryption Library"><span class="fa fa-arrow-circle-left"></span> Previous</a>
  880. </div>
  881. <hr/>
  882. <div role="contentinfo">
  883. <p>
  884. &copy; Copyright 2014 - 2019, British Columbia Institute of Technology.
  885. Last updated on Sep 19, 2019.
  886. </p>
  887. </div>
  888. Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
  889. </footer>
  890. </div>
  891. </div>
  892. </section>
  893. </div>
  894. <script type="text/javascript">
  895. var DOCUMENTATION_OPTIONS = {
  896. URL_ROOT:'../',
  897. VERSION:'3.1.11',
  898. COLLAPSE_INDEX:false,
  899. FILE_SUFFIX:'.html',
  900. HAS_SOURCE: false
  901. };
  902. </script>
  903. <script type="text/javascript" src="../_static/jquery.js"></script>
  904. <script type="text/javascript" src="../_static/underscore.js"></script>
  905. <script type="text/javascript" src="../_static/doctools.js"></script>
  906. <script type="text/javascript" src="../_static/js/theme.js"></script>
  907. <script type="text/javascript">
  908. jQuery(function () {
  909. SphinxRtdTheme.StickyNav.enable();
  910. });
  911. </script>
  912. </body>
  913. </html>