philip Tue Jul 16 13:56:12 2002 EDT
Modified files:
/phpdoc/en/features file-upload.xml
Log:
* Removed duplicate var list showing register_globals = on variables,
put this in a paragraph instead.
* Added ['error'] to the variable list.
* Rewrote many parts, to make it clearer. Added many links.
Index: phpdoc/en/features/file-upload.xml
diff -u phpdoc/en/features/file-upload.xml:1.48 phpdoc/en/features/file-upload.xml:1.49
--- phpdoc/en/features/file-upload.xml:1.48 Tue Jul 16 13:11:34 2002
+++ phpdoc/en/features/file-upload.xml Tue Jul 16 13:56:12 2002
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.48 $ -->
+<!-- $Revision: 1.49 $ -->
<chapter id="features.file-upload">
<title>Handling file uploads</title>
@@ -50,34 +50,24 @@
</para>
<para>
- Variables defined for uploaded files differs depends on PHP
- version and configuration. Following variables will be defined
- within the destination script upon a successful upload. When <link
- linkend="ini.track-vars">track_vars</link> is enabled,
- $HTTP_POST_FILES/$_FILES array is initialized. Finally, related
- variables may be initialized as globals when
- <link linkend="ini.register-globals">register_globals</link>
- is turned on. However, use of globals is not recommended anymore.
- </para>
- <note>
- <para>
- <link linkend="ini.track-vars">track_vars</link> is always on
- from PHP 4.0.3. From PHP 4.1.0 or later, $_FILES may be used
- instead of
- <varname>$HTTP_POST_FILES</varname>. <varname>$_FILES</varname> is
- always global, so <literal>global</literal> should not be used
- for $_FILES in function scope.
- </para>
- </note>
- <para>
- <varname>$HTTP_POST_FILES</varname>/<varname>$_FILES</varname> is
- provided to contain the uploaded file information.
- </para>
-
- <para>
- The contents of <varname>$_FILES</varname> are as
- follows. Note that this assumes the use of the file upload name
- 'userfile', as used in the example script above:
+ The Variables defined for uploaded files differs depending on
+ the PHP version and configuration. The autoglobal
+ <link linkend="reserved.variables.files">$_FILES</link>
+ exists as of PHP 4.1.0 The <varname>$HTTP_POST_FILES</varname> array
+ has existed since PHP 4.0.0. These arrays will contain all
+ your uploaded file information. Using <varname>$_FILES</varname>
+ is preferred. If the PHP directive
+ <link linkend="ini.register-globals">register_globals</link> is
+ <emphasis>on</emphasis>, related variable names will also exist.
+ <link linkend="ini.register-globals">register_globals</link>
+ defaults to <emphasis>off</emphasis> as of PHP
+ <ulink url="&url.php.release4.2.0;">4.2.0</ulink>.
+ </para>
+ <para>
+ The contents of <link linkend="reserved.variables.files">$_FILES</link>
+ from our example script is as follows. Note that this assumes the use of
+ the file upload name <emphasis>userfile</emphasis>, as used in the example
+ script above.
<variablelist>
<varlistentry>
<term><varname>$_FILES['userfile']['name']</varname></term>
@@ -114,61 +104,38 @@
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>$_FILES['userfile']['error']</varname></term>
+ <listitem>
+ <para>
+ The <link linkend="features.file-upload.errors">error code</link>
+ associated with this file upload. <emphasis>['error']</emphasis>
+ was added in PHP 4.2.0
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</para>
<note>
<para>
In PHP versions prior 4.1.0 this was named
- <varname>$HTTP_POST_FILES</varname> and was not an autoglobal variable.
- PHP 3 does not support <varname>$HTTP_POST_FILES</varname>.
+ <varname>$HTTP_POST_FILES</varname> and it's not an
+ <link linkend="language.variables.superglobals">autoglobal</link>
+ variable like <varname>$_FILES</varname> is. PHP 3 does not
+ support <varname>$HTTP_POST_FILES</varname>.
</para>
</note>
-
<para>
When <link linkend="ini.register-globals">register_globals</link>
- is turned on in &php.ini; the available variables
- are as follows. Note that the following variable names assume the
- use of the file upload name 'userfile', as used in the example
- script above:
-
- <itemizedlist>
- <listitem>
- <simpara>
- <varname>$userfile</varname> - The temporary filename in which
- the uploaded file was stored on the server machine.
- </simpara>
- </listitem>
- <listitem>
- <simpara>
- <varname>$userfile_name</varname> - The original name or path
- of the file on the sender's system.
- </simpara>
- </listitem>
- <listitem>
- <simpara>
- <varname>$userfile_size</varname> - The size of the uploaded
- file in bytes.
- </simpara>
- </listitem>
- <listitem>
- <simpara>
- <varname>$userfile_type</varname> - The mime type of the file
- if the browser provided this information. An example would be
- "image/gif".
- </simpara>
- </listitem>
- </itemizedlist>
- Note that the "<varname>$userfile</varname>" part of the above
- variables is whatever the name of the <input> field of
- type="file" is in the upload form. In the above upload form
- example, we chose to call it "userfile".
+ is turned <emphasis>on</emphasis> in &php.ini;, additional
+ variables are available. For example,
+ <varname>$userfile_name</varname> will equal
+ <varname>$_FILES['userfile']['name']</varname>,
+ <varname>$userfile_type</varname> will equal
+ <varname>$_FILES['userfile']['type']</varname>, etc. Keep in mind
+ that as of PHP 4.2.0, register_globals defaults to off. It's
+ preferred to not rely on this directive.
</para>
- <note>
- <para>
- <literal>register_globals = On</literal> is not recommended for
- security and performance reason.
- </para>
- </note>
<para>
Files will by default be stored in the server's default temporary
directory, unless another location has been given with the <link
@@ -213,6 +180,9 @@
could use the
<varname>$_FILES['userfile']['type']</varname> variable
to throw away any files that didn't match a certain type criteria.
+ As of PHP 4.2.0, you could use <varname>$_FILES['userfile']['error']</varname>
+ and plan your logic according to the <link
+ linkend="features.file-upload.errors">error codes</link>.
Whatever the logic, you should either delete the file from the
temporary directory or move it elsewhere.
</simpara>
@@ -227,7 +197,7 @@
<simpara>
Since PHP 4.2.0, PHP returns an appropriate error code along with the
file array. The error code can be found in the
- <emphasis>["error"]</emphasis> segment of the file array that is created
+ <emphasis>['error']</emphasis> segment of the file array that is created
during the file upload by PHP. In otherwords, the error might be
found in <varname>$_FILES['userfile']['error']</varname>.
</simpara>
--
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php