mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
. 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:
parent
35e260727a
commit
4dbbde4f9d
1 changed files with 34 additions and 25 deletions
|
@ -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>
|
||||
<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 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: <INPUT NAME="userfile" TYPE="file">
|
|||
<simpara>
|
||||
<varname>$userfile_type</varname> - The mime type of the file
|
||||
if the browser provided this information. An example would be
|
||||
"image/gif".
|
||||
"image/gif".
|
||||
</simpara>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
Note that the "$userfile" 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
|
||||
"userfile"
|
||||
"userfile"
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
@ -119,7 +121,7 @@ Send this file: <INPUT NAME="userfile" TYPE="file">
|
|||
<para>
|
||||
The mime type of the file, if the browser provided this
|
||||
information. An example would be
|
||||
<literal>"image/gif"</literal>.
|
||||
<literal>"image/gif"</literal>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -163,7 +165,8 @@ Send this file: <INPUT NAME="userfile" TYPE="file">
|
|||
<function>move_uploaded_file</function>.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<?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");
|
||||
?>
|
||||
?>
|
||||
]]>
|
||||
</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">
|
||||
<?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">
|
||||
<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>
|
||||
<![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>
|
||||
<?php copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?>
|
||||
<![CDATA[
|
||||
<?php copy($PHP_UPLOADED_FILE_NAME,$DOCUMENT_ROOT.$REQUEST_URI); ?>
|
||||
]]>
|
||||
</programlisting></informalexample>
|
||||
</para>
|
||||
<simpara>
|
||||
|
|
Loading…
Reference in a new issue