features.file-upload.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 280 行 · 第 1/2 页

HTML
280
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Handling file uploads</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.xforms.html">Dealing with XForms</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.file-upload.errors.html">Error Messages Explained</a></div> <div class="up"><a href="features.html">Features</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div>  <h1>Handling file uploads</h1><h2>Table of Contents</h2><ul class="chunklist chunklist_chapter"><li><a href="features.file-upload.errors.html">Error Messages Explained</a></li><li><a href="features.file-upload.common-pitfalls.html">Common Pitfalls</a></li><li><a href="features.file-upload.multiple.html">Uploading multiple files</a></li><li><a href="features.file-upload.put-method.html">PUT method support</a></li></ul>  <div id="features.file-upload.post-method" class="sect1">   <h2 class="title">POST method uploads</h2>   <p class="simpara">    This feature lets people upload both text and binary files.     With PHP&#039;s authentication and file manipulation functions,    you have full control over who is allowed to upload and    what is to be done with the file once it has been uploaded.   </p>   <p class="simpara">    PHP is capable of receiving file uploads from any RFC-1867    compliant browser (which includes <span class="productname">Netscape Navigator 3</span>     or later, <span class="productname">Microsoft Internet Explorer 3</span>     with a patch from Microsoft, or later without a patch).   </p>   <blockquote><p><b class="note">Note</b>:     <b>Related Configurations Note</b><br />         See also the <a href="ini.core.html#ini.file-uploads" class="link">file_uploads</a>,      <a href="ini.core.html#ini.upload-max-filesize" class="link">upload_max_filesize</a>,     <a href="ini.core.html#ini.upload-tmp-dir" class="link">upload_tmp_dir</a>,     <a href="ini.core.html#ini.post-max-size" class="link">post_max_size</a> and     <a href="info.configuration.html#ini.max-input-time" class="link">max_input_time</a> directives      in <var class="filename">php.ini</var>    <br />   </p></blockquote>   <p class="para">    PHP also supports PUT-method file uploads as used by    <span class="productname">Netscape Composer</span> and W3C&#039;s     <span class="productname">Amaya</span> clients.  See the <a href="features.file-upload.put-method.html" class="link">PUT Method    Support</a> for more details.   </p>   <p class="para">    <div class="example">     <p><b>Example #1 File Upload Form</b></p>     <div class="example-contents"><p>      A file upload screen can be built by creating a special form which      looks something like this:     </p></div>     <div class="example-contents"><div class="cdata"><pre>&lt;!-- The data encoding type, enctype, MUST be specified as below --&gt;&lt;form enctype=&quot;multipart/form-data&quot; action=&quot;__URL__&quot; method=&quot;POST&quot;&gt;    &lt;!-- MAX_FILE_SIZE must precede the file input field --&gt;    &lt;input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;30000&quot; /&gt;    &lt;!-- Name of input element determines name in $_FILES array --&gt;    Send this file: &lt;input name=&quot;userfile&quot; type=&quot;file&quot; /&gt;    &lt;input type=&quot;submit&quot; value=&quot;Send File&quot; /&gt;&lt;/form&gt;</pre></div>     </div>     <div class="example-contents"><p>      The <i>__URL__</i> in the above example should be replaced,      and point to a PHP file.     </p></div>     <div class="example-contents"><p>      The <i>MAX_FILE_SIZE</i> hidden field (measured in bytes) must      precede the file input field, and its value is the maximum filesize accepted by PHP.      Fooling this setting on the browser side is quite easy, so never rely      on files with a greater size being blocked by this feature.      The PHP settings for maximum-size, however, cannot be fooled.      This form element should always be used as it      saves users the trouble of waiting for a big file being transferred only      to find that it was too big and the transfer failed.     </p></div>    </div>   </p>   <blockquote><p><b class="note">Note</b>:          Be sure your file upload form has attribute <i>enctype=&quot;multipart/form-data&quot;</i>     otherwise the file upload will not work.    <br />   </p></blockquote>   <p class="para">    The global <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES</a></var>    exists as of PHP 4.1.0 (Use <var class="varname">$HTTP_POST_FILES</var>    instead if using an earlier version).    These arrays will contain all the uploaded file information.   </p>   <p class="para">    The contents of <var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES</a></var>    from the example form is as follows. Note that this assumes the use of     the file upload name <em class="emphasis">userfile</em>, as used in the example     script above. This can be any name.    <dl>     <dt>      <span class="term"><var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['name']</a></var></span>      <dd>       <p class="para">        The original name of the file on the client machine.       </p>      </dd>     </dt>     <dt>      <span class="term"><var class="varname"><a href="reserved.variables.files.html" class="classname">$_FILES['userfile']['type']</a></var></span>      <dd>       <p class="para">        The mime type of the file, if the browser provided this        information.  An example would be        <i>&quot;image/gif&quot;</i>. This mime type is however        not checked on the PHP side and therefore don&#039;t take its value        for granted.       </p>      </dd>     </dt>     <dt>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?