philip Sat Jan 18 03:34:26 2003 EDT
Modified files:
/phpdoc/en/features file-upload.xml
Log:
Updating the file upload processing example to focus on move_uploadad_file. This
closes bug #20572. Expanded example a bit too. Also raised the MAX_FILE_SIZE
limit in the form from 1000 to 30000.
Index: phpdoc/en/features/file-upload.xml
diff -u phpdoc/en/features/file-upload.xml:1.54 phpdoc/en/features/file-upload.xml:1.55
--- phpdoc/en/features/file-upload.xml:1.54 Sun Jan 5 15:37:39 2003
+++ phpdoc/en/features/file-upload.xml Sat Jan 18 03:34:25 2003
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.54 $ -->
+<!-- $Revision: 1.55 $ -->
<chapter id="features.file-upload">
<title>Handling file uploads</title>
@@ -39,7 +39,7 @@
<programlisting role="html">
<![CDATA[
<form enctype="multipart/form-data" action="_URL_" method="post">
-<input type="hidden" name="MAX_FILE_SIZE" value="1000">
+<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
@@ -160,22 +160,27 @@
<example>
<title>Validating file uploads</title>
<para>
- The following examples are for versions of PHP 4 greater than
- 4.0.2. See the function entries for
- <function>is_uploaded_file</function> and
- <function>move_uploaded_file</function>.
+ See also the function entries for <function>is_uploaded_file</function>
+ and <function>move_uploaded_file</function> for further information. The
+ following example will process the file upload that came from a form.
</para>
<programlisting role="php">
<![CDATA[
-<?php
-// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
-if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
- copy($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
+<?php
+// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES.
+// In PHP earlier then 4.0.3, use copy() and is_uploaded_file() instead of
+move_uploaded_file
+
+$uploaddir = '/var/www/uploads/';
+
+print "<pre>";
+if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir .
+$_FILES['userfile']['name'])) {
+ print "File is valid, and was successfully uploaded. Here's some more debugging
+info:\n";
+ print_r($_FILES);
} else {
- echo "Possible file upload attack. Filename: " . $_FILES['userfile']['name'];
+ print "Possible file upload attack! Here's some debugging info:\n";
+ print_r($_FILES);
}
-/* ...or... */
-move_uploaded_file($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
+
?>
]]>
</programlisting>
--
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php