. The best place to show how <![CDATA[ ... ]]> can help...

. Converting all HTML tags to lowecased ones
 . Using correct <filename> instead of other bad ones
 . Adding role="html" to HTML example


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@55442 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Gabor Hojtsy 2001-08-19 13:20:42 +00:00
parent 35e260727a
commit 4dbbde4f9d

View file

@ -1,5 +1,5 @@
<?xml encoding="iso-8859-1"?>
<!-- $Revision: 1.23 $ -->
<!-- $Revision: 1.24 $ -->
<chapter id="features.file-upload">
<title>Handling file uploads</title>
@ -26,12 +26,14 @@
looks something like this:
<example>
<title>File Upload Form</title>
<programlisting>
&lt;FORM ENCTYPE=&quot;multipart/form-data&quot; ACTION=&quot;_URL_&quot; METHOD=&quot;POST&quot;&gt;
&lt;INPUT TYPE=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;1000&quot;&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;
<programlisting role="html">
<![CDATA[
<form enctype="multipart/form-data" action="_URL_" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
]]>
</programlisting>
</example>
The _URL_ should point to a PHP file. The MAX_FILE_SIZE hidden
@ -81,14 +83,14 @@ Send this file: &lt;INPUT NAME=&quot;userfile&quot; TYPE=&quot;file&quot;&gt;
<simpara>
<varname>$userfile_type</varname> - The mime type of the file
if the browser provided this information. An example would be
&quot;image/gif&quot;.
"image/gif".
</simpara>
</listitem>
</itemizedlist>
Note that the &quot;$userfile&quot; part of the above variables is
Note that the "$userfile" 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
&quot;userfile&quot;
"userfile"
</para>
<para>
@ -119,7 +121,7 @@ Send this file: &lt;INPUT NAME=&quot;userfile&quot; TYPE=&quot;file&quot;&gt;
<para>
The mime type of the file, if the browser provided this
information. An example would be
<literal>&quot;image/gif&quot;</literal>.
<literal>"image/gif"</literal>.
</para>
</listitem>
</varlistentry>
@ -163,7 +165,8 @@ Send this file: &lt;INPUT NAME=&quot;userfile&quot; TYPE=&quot;file&quot;&gt;
<function>move_uploaded_file</function>.
</para>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
if (is_uploaded_file($userfile)) {
copy($userfile, "/place/to/put/uploaded/file");
} else {
@ -171,7 +174,8 @@ if (is_uploaded_file($userfile)) {
}
/* ...or... */
move_uploaded_file($userfile, "/place/to/put/uploaded/file");
?&gt;
?>
]]>
</programlisting>
<para>
For earlier versions of PHP, you'll need to do something like
@ -185,7 +189,8 @@ move_uploaded_file($userfile, "/place/to/put/uploaded/file");
</note>
</para>
<programlisting role="php">
&lt;?php
<![CDATA[
<?php
/* Userland test for uploaded file. */
function is_uploaded_file($filename) {
if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
@ -202,6 +207,7 @@ if (is_uploaded_file($userfile)) {
echo "Possible file upload attack: filename '$userfile'.";
}
?>
]]>
</programlisting>
</example>
</para>
@ -226,8 +232,7 @@ if (is_uploaded_file($userfile)) {
<title>Common Pitfalls</title>
<simpara>
The <literal>MAX_FILE_SIZE</literal> item cannot specify a file size
greater than the file
size that has been set in the <link
greater than the file size that has been set in the <link
linkend="ini.upload-max-filesize">upload_max_filesize</link> ini-setting.
The default is 2 Megabytes.
</simpara>
@ -260,12 +265,14 @@ if (is_uploaded_file($userfile)) {
<example>
<title>Uploading multiple files</title>
<programlisting role="html">
&lt;form action=&quot;file-upload.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
Send these files:&lt;br&gt;
&lt;input name=&quot;userfile[]&quot; type=&quot;file&quot;&gt;&lt;br&gt;
&lt;input name=&quot;userfile[]&quot; type=&quot;file&quot;&gt;&lt;br&gt;
&lt;input type=&quot;submit&quot; value=&quot;Send files&quot;&gt;
&lt;/form&gt;
<![CDATA[
<form action="file-upload.php" method="post" enctype="multipart/form-data">
Send these files:<br>
<input name="userfile[]" type="file"><br>
<input name="userfile[]" type="file"><br>
<input type="submit" value="Send files">
</form>
]]>
</programlisting>
</example>
</para>
@ -283,10 +290,10 @@ if (is_uploaded_file($userfile)) {
<filename>/home/test/review.html</filename> and
<filename>/home/test/xwp.out</filename> are submitted. In this
case, <varname>$userfile_name[0]</varname> would
contain the value <literal>review.html</literal>,
contain the value <filename>review.html</filename>,
and <varname>$userfile_name[1]</varname> would
contain the value
<varname>xwp.out</varname>. Similarly,
<filename>xwp.out</filename>. Similarly,
<varname>$userfile_size[0]</varname> would contain
<filename>review.html</filename>'s filesize, and so forth.
</simpara>
@ -339,7 +346,9 @@ Script PUT /put.php
</simpara>
<para>
<informalexample><programlisting>
&lt;?php copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?&gt;
<![CDATA[
<?php copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?>
]]>
</programlisting></informalexample>
</para>
<simpara>