PHP: ファイルアップロードの処理 - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<XFormsの処理エラーメッセージの説明>
view the version of this page
Last updated: Tue, 21 Dec 2004

第 37章ファイルアップロードの処理

POST メソッドによるアップロード

PHP は、全てのRFC-1867対応ブラウザ(Netscape Navigator 3 以上、 MicrosoftからのパッチをあてたMicrosoft Internet Explorer 3または パッチ無しのそれ以降の版を含みます)からファイルのアップロードを 受けることができます。 この機能では、テキストとバイナリファイルの両方のアップロードが可能です。 PHPの認証機構およびファイル操作関数を用いて、アップロードを許可する ユーザーとアップロード後にそのファイルを使用して行う動作を完全に制御する ことが可能です。

関係する設定に関する注記: php.inifile_uploads, upload_max_filesize, upload_tmp_dir post_max_size ディレクティブ も参照下さい。

PHPはNetscape ComposerおよびW3CのAmayaクライアントにより使用される PUTメソッドによるファイルアップロードもサポートしていることに注意 して下さい。詳細は、PUTメソッドのサポート を参照下さい。

ファイルアップロード画面は、次のような特別なフォームを作成すること により、作成することができます。

例 37-1. ファイルアップロード用のフォーム

<form enctype="multipart/form-data" action="_URL_" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
_URL_ はPHPファイルを指す必要があります。hidden フィールド MAX_FILE_SIZEは、input フィールド file の前に置く必要があります。 この値は、取得可能なファイルの最大サイズを規定します。この値はバイ ト数で指定します。

警告

MAX_FILE_SIZEはブラウザへの勧告に過ぎません。この最大値を 出し抜くのは簡単なことなので信頼してはいけません。しかし、 PHP側の最大サイズの設定を欺くことはできません。 しかしそれでもMAX_FILE_SIZEを指定すべきです。なぜなら、 巨大なファイルを転送しようとして、実はそれが大きすぎて 転送できないということを長時間待ったあとで知らされるのを 防げるからです。

ファイルのアップロードに際して定義される変数はPHPのバージョン及び 設定により異なります。 オートグローバル$_FILES は、PHP 4.1.0以降に存在します。 $HTTP_POST_FILESは、PHP 4.0.0以降に存在します。 これらの配列には、全てアップロードされたファイルの情報が 含まれています。$_FILESの使用が推奨されています。 PHPディレクティブ register_globalsonの場合、関係する変数名も存在します。 register_globals は、PHP 4.2.0 以降、offがデフォルトとなっています。

$_FILES の内容は次のようになります。ここでは、上の例のスクリプトで使われたように、 アップロードファイルの名前としてuserfileを使用する ことを仮定していることに注意して下さい。 実際にはどんな名前にすることもできます。

$_FILES['userfile']['name']

クライアントマシンの元のファイル名。

$_FILES['userfile']['type']

ファイルのMIME型。ただし、ブラウザがこの情報を提供する場合。 例えば、"image/gif"のようになります。

$_FILES['userfile']['size']

アップロードされたファイルのバイト単位のサイズ。

$_FILES['userfile']['tmp_name']

アップロードされたファイルがサーバー上で保存されているテンポラ リファイルの名前。

$_FILES['userfile']['error']

このファイルアップロードに関する エラーコード ['error']は、PHP 4.2.0で追加されました。

注意: 4.1.0より前のバージョンのPHPでは、この変数は $HTTP_POST_FILESで、$_FILESの ような オートグローバル 変数ではありませんでした。PHP 3は、 $HTTP_POST_FILESをサポートしていません。

php.iniregister_globalsonとなっている場合、追加の変数が利用可能となります。 例えば、$userfile_nameは、 $_FILES['userfile']['name']と同じで、 $userfile_typeは、 $_FILES['userfile']['type']と同じといったようになります。 PHP 4.2.0以降は、register_globalsのデフォルトはoffであることを 留意下さい。このディレクティブに依存しないことが推奨されます。

php.iniupload_tmp_dirディレクティブで 他の場所を指定しない限り、ファイルはサーバーにおけるデフォルトのテ ンポラリディレクトリに保存されます。サーバーのデフォルトディレクト リは、PHP を実行する環境において環境変数 TMPDIRを設 定することにより変更することができます。しかし、PHP スクリプトの内 部からputenv() 関数により設定しても上手くいきま せん。この環境変数は、アップロードされたファイルに他の処理を行う際 にも同様に使用することが可能です。

例 37-2. ファイルのアップロードを検証する

以下の例は、4.0.2 より後のバージョンの PHP 4 用です。 is_uploaded_file() およびmove_uploaded_file()の関数のエントリを 参照下さい。以下はフォームからファイルをアップロードするプロセスの例です。

<?php
// 4.1.0より前のPHPでは$FILESの代わりに$HTTP_POST_FILESを使用する必要
// があります。4.0.3より前のPHPではmove_uploaded_fileの代わりにcopy() と
// is_uploaded_file()を使用してください

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];

print
"<pre>";
if (
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   print
"File is valid, and was successfully uploaded. ";
   print
"Here's some more debugging info:\n";
  
print_r($_FILES);
} else {
   print
"ファイルアップロード攻撃をされた可能性があります。デバッグ関連情報:\n";
  
print_r($_FILES);
}

?>

アップロードされたファイルを受け取る PHP スクリプトは、アップロー ドされたファイルを用いて何をするべきかを決めるために必要なロジック を全て実装する必要があります。例えば、変数 $_FILES['userfile']['size']を使用して、小さすぎ たり、大きすぎたりするファイルを捨てることができます。指定した型以 外のファイルを全て捨てるために変数 $_FILES['userfile']['type']を用いることができま す。 PHP 4.2.0以降、 $_FILES['userfile']['error'] を使用することができ、 エラーコード に基づき、ロジックを構成することができます。 何らかの方法により、テンポラリディレクトリからファイルを削除し たり、他の場所に移動したりする必要があります。

移動または名前の変更が行われていない場合、リクエストの終了時にその ファイルはテンポラリディレクトリから削除されます。



add a note add a note User Contributed Notes
ファイルアップロードの処理
27-Feb-2005 06:06
Just to remind everyone, if you are wanting to upload larger files, you will need to change the value of both upload_max_filesize and post_max_size to the largest filesize you would like to allow.  Then restart apache and everything should work.
infoworks-tn dot com at david dot hamilton dot nospam
27-Feb-2005 04:52
Regarding the post by therebechips below about saving attachments to a MySQL database.  Here are some items that he forgot to mention:

Make sure your datafield is type text for storing the chunks in.  base64_encode translates binary into text (in a nutshell). 

Also, the max size for a text field is 65535.  In his example he used 50,000 for the MAX_SQL chunks to put into the database.  If you do this, the encoded data is too large to fit in the field and is truncated.  Use 40,000 instead to be safe.  It took me a few hours to realize why my images were coming back out of the database corrupted.

Other than that, his example worked very well. 
If you want to email me, flip the two parts of my email address around and remove .nospam

David Hamilton
Leevi at izilla dot com dot au
09-Feb-2005 06:52
This may help a newbie to file uploads.. it took advice from a friend to fix it..

If you are using
-windows xp
-iis 5
-php 5

If you keep getting permission errors on file uploads... and you have sworn you set the permissions to write to the directory in iis...

double check that
a) in windows explorer under tools > folder options
click the view tab
scroll down all the way to "use simple file sharing (recommended)"
uncheck this box

b) find the folder you wish to upload to on your server
c) click properties and then the security tab
d) make sure the appropriate write settings are checked.

you may want to test by setting "everyone" to have full permission....

BEWARE doing this will open up big security holes on your server....

hope this helps

Leevi Graham
phpnoob at adam dot net dot nz
09-Feb-2005 01:57
Just thought I'd add this since I had to search forever to find an answer. 

When I used the enctype attribute on a form to process a file upload I had a problem redirecting back to an anchor point on the original page my code looked like this on the upload page:

header("Location: original_page.php#image_gal");

and the resulting url looked like this:



note the missing anchor reference.  So my work around was to pass the anchor point as a variable and then redirect again when I got to the original page.  A little bit chunky but it worked.  Hope this helps someone.
Tyfud
07-Jan-2005 04:44
It's important to note that when using the move_uploaded_file() command, that some configurations (Especially IIS) will fail if you prefix the destination path with a leading "/". Try the following:

move_uploaded_file($tmpFileName,'uploads/'.$fileName);

Setting up permissions is also a must. Make sure all accounts have write access to your upload directory, and read access if you wish to view these files later. You might have to chmod() the directory or file afterwards as well if you're still getting access errors.
lobo235 at gmail dot com
04-Jan-2005 10:48
Be sure to be careful with the $_FILES['userfile']['name'] array element. If the client uploads a file that has an apostrophe in the filename it WILL NOT get set to the full name of the file from the client's machine.

For example, if the client uploads a file named george's car.jpg the $_FILES['userfile']['name'] element will be set to s car.jpg because PHP appears to cut off everything before the apostrophe as well as the apostrophe itself.

This did not happen in some of the previous versions of PHP but I know that it happens in version 4.3.10 so watch out for this.

I thought this was a bug so I submitted it but it turns out that it is a "security measure"
ryan dot baclit at gmail dot com
15-Dec-2004 07:15
Hello everyone. I want to share to you that uploading will never work out of the box if you didn't set the upload_tmp_dir directive in your php.ini file in the first place. If you just compiled the source files as is and tried to upload, you're in for a big mess. I don't know the flags to pass to the configure script to tell php about the default temporary directory to place the uploaded files.

In case your php upload code won't do as expected, open up the php.ini file and set the upload_tmp_dir. Then restart the Apache server and you're set.

By the way, I'm using Linux Mandrake 10.1 Official and PHP 4.3.9 on Apache 2.0.49.
captlid
08-Nov-2004 06:37
mime_content_type() is better to use if you want to find if a file sent is really a jpeg or a plain text file. :)
dev at kiwicore dot org
13-Oct-2004 07:58
Becuase uploading seems to rarely work "out of the box" even if you follow the above instructions, I'll reiterate: the main reason people fail to have successful uploads, is because the directory that you are uploading to must have the right permissions, 0755 seems to work fine. I'd also like to submit my shot at an end all, be all upload capturing script.

Usage :

list($success,$response) = captureUpload('./user_images/',false,'_upload');

Will look inside $_FILES['upload'] for an uploaded file. The second parameter is the name of a callbaack function (false, if you don't want it), to rename the file, it will send two parameters:
  
     $file (array of file info) , $destinationDirectory

It should return the name of the file. This is useful if you want to do a database lookup (for CMS integration, to see who uploaded it, etc), or do some other fancy checking.

The function will also rename file "whatever_copy_1.gif" if "whatever.gif" already exists.

And here is the code:

function captureUpload($destDir,$nameCallback = false,$fieldName = '_upload',$maxFileSize = false){
  
   //make sure something is there
   if(!isset($_FILES[$fieldName]) ||!isset($_FILES)||!is_array($_FILES[$fieldName]) ||!$_FILES[$fieldName]['name'])
       return array(false,'No files were uploaded. Make sure your form tag\'s enctype was set to multipart/form-data and that the right field is being checked for the uploaded file.');
  
   //normalize the file variable
   $file = $_FILES[$fieldName];
   if (!isset($file['type']))      $file['type']      = '';
   if (!isset($file['size']))      $file['size']      = '';
   if (!isset($file['tmp_name']))  $file['tmp_name']  = '';
   $file['name'] = preg_replace(
             '/[^a-zA-Z0-9\.\$\%\'\`\-\@\{\}\~\!\#\(\)\&\_\^]/'
             ,'',str_replace(array(' ','%20'),array('_','_'),$file['name']));
  
   //was it to big?
   if($maxFileSize && ($file['size'] > $maxFileSize))
       return array(false,'The file uploaded was to large.');
  
   //normalize destDir
   if(strlen($destDir)>0 && $destDir[strlen($destDir)-1] != "/")
       $destDir = $destDir.'/';
      
   //should we change the filename via a callback?
   if($nameCallback)
       $file['name'] = call_user_func_array($nameCallback, array($file,$destDir));
  
   $i = 0;   
   //if the filename already exists, append _copy_x (with extension)
   if(strpos($file['name'],'.') !== false){
       $bits = explode('.',$file['name']);
       $ext = array_pop($bits);
       while(file_exists($destDir.implode('.', $bits).($i?'_copy_'.$i:'').'.'.$ext)){
           ++$i;
           $file['name'] = implode('.',$bits).($i?'_copy_'.$i:'').'.'.$ext;
       }
  
   //if the filename already exists, append _copy_x (no extension)
   } else {
       while(file_exists($destDir.$file['name'].($i ?'_copy_'.$i:''))){
           ++$i;
           $file['name'] = $file['name'].($i?'_copy_'.$i:'');
       }
   }
  
   //and now the big moment
   if(!@copy($file['tmp_name'], $destDir.$file['name']))
       return array(false,'Could not write the file "'.$file['name'].'" to: "'.$destDir.'". Permission denied.');
   else
       return array(true,$file['name']);
}
therhinoman at hotmail dot com
27-Aug-2004 08:20
If your upload script is meant only for uploading images, you can use the image function getimagesize() (does not require the GD image library) to make sure you're really getting an image and also filter image types.

<?php getimagesize($file); ?>

...will return false if the file is not an image or is not accessable, otherwise it will return an array...

<?php
$file
= 'somefile.jpg';

# assuming you've already taken some other
# preventive measures such as checking file
# extensions...

$result_array = getimagesize($file);

if (
$result_array !== false) {
  
$mime_type = $result_array['mime'];
   switch(
$mime_type) {
       case
"image/jpeg":
           echo
"file is jpeg type";
           break;
       case
"image/gif":
           echo
"file is gif type";
           break;
       default:
           echo
"file is an image, but not of gif or jpeg type";
   }
} else {
   echo
"file is not a valid image file";
}
?>

using this function along with others mentioned on this page, image ploading can be made pretty much fool-proof.

See for supported image types and more info.
olijon, iceland
19-Jun-2004 03:24
When uploading large images, I got a "Document contains no data" error when using Netscape and an error page when using Explorer. My server setup is RH Linux 9, Apache 2 and PHP 4.3.

I found out that the following entry in the httpd.conf file was missing:

<Files *.php>
  SetOutputFilter PHP
  SetInputFilter PHP
  LimitRequestBody 524288 (max size in bytes)
</Files>

When this had been added, everything worked smoothly.

- Oli Jon, Iceland
brion at pobox dot com
11-May-2004 01:08
Note that with magic_quotes_gpc on, the uploaded filename has backslashes added *but the tmp_name does not*. On Windows where the tmp_name path includes backslashes, you *must not* run stripslashes() on the tmp_name, so keep that in mind when de-magic_quotes-izing your input.
steve dot criddle at crd-sector dot com
16-Apr-2004 06:43
IE on the Mac is a bit troublesome.  If you are uploading a file with an unknown file suffix, IE uploads the file with a mime type of "application/x-macbinary".  The resulting file includes the resource fork wrapped around the file.  Not terribly useful.

The following code assumes that the mime type is in $type, and that you have loaded the file's contents into $content.  If the file is in MacBinary format, it delves into the resource fork header, gets the length of the data fork (bytes 83-86) and uses that to get rid of the resource fork.

(There is probably a better way to do it, but this solved my problem):

<?php
if ($type == 'application/x-macbinary') {
   if (
strlen($content) < 128) die('File too small');
  
$length = 0;
   for (
$i=83; $i<=86; $i++) {
      
$length = ($length * 256) + ord(substr($content,$i,1));
         }
  
$content = substr($content,128,$length);
}
?>
hisham
02-Mar-2004 06:54
On a similar note to jim dot dam at sympatico dot ca 27-Feb-2002 09:13

Browsers intepret png upload type differently too eg.

print_r() output from Mozilla 1.6
Array ( [name] => eg1.png [type] => image/png [tmp_name] => /var/tmp/phpIJd4FL [error] => 0 [size] => 66614 )

print_r() output from IE 6
Array ( [name] => eg1.png [type] => image/x-png [tmp_name] => /var/tmp/phpHJ04Dh [error] => 0 [size] => 66614 )

Note the difference of image/png and image/x-png type intepretation of the same image file.

Further note:
~caetin~ ( at ) ~hotpop~ ( dot ) ~com~
11-Feb-2004 04:37
From the manual:

     If no file is selected for upload in your form, PHP will return $_FILES['userfile']['size'] as 0, and $_FILES['userfile']['tmp_name'] as none.

As of PHP 4.2.0, the "none" is no longer a reliable determinant of no file uploaded. It's documented if you click on the "error codes" link, but you need to look at the $_FILES['your_file']['error']. If it's 4, then no file was selected.
maya_gomez ~ at ~ mail ~ dot ~ ru
06-Feb-2004 01:20
when you upload the file, $_FILES['file']['name'] contains its original name converted into server's default charset.
if a name contain characters that aren't present in default charset, the conversion fails and the $_FILES['file']['name'] remains in original charset.

i've got this behavior when uploading from a windows-1251 environment into koi8-r. if a filename has the number sign "�" (0xb9), it DOES NOT GET CONVERTED as soon as there is no such character in koi8-r.

Workaround i use:

<?php
if (strstr ($_FILES['file']['name'], chr(0xb9)) != "")
{
  
$_FILES['file']['name'] = iconv (
      
"windows-1251",
      
"koi8-r",
      
str_replace (chr(0xb9), "N.", $_FILES['file']['name']));
};
?>
srikanth at ideaworks3d dot com
19-Jan-2004 06:18
If the file is empty (0 bytes) it is treated as if no file
is uploaded. $_FILES['userfile']['tmp_name'] returns "none".
Shekhar Govindarajan
26-Oct-2003 01:38
To upload large files, besides setting upload_max_filesize, you must also set post_max_size in php.ini or using ini_set() function. Keep the value to more than the maximum expected size of the upload. This is because, you may be sending other post data along with the upload file. For example:

post_max_size = 601M

This should be a safe setting if you want to upload files of around 600 MB (as specified by upload_max_filesize = 600M)

While uploading large files, you should also increase the values for max_execution_time  and max_input_time directives. Else your script will timeout or timeout before being able to parse the entire input/uploaded data.
therebechips
06-Sep-2003 09:02
Re: Handling uploads and downloads of large files and storing in MySQL.

Use two tables to store data about the file and the file data itself. ***Important: to preserve the integrity of the data use base64_encode() NOT addslashes().

<?php
// Max packet size
  
define("MAX_SQL",50000);
  
$filehandle = fopen($tmp, "rb") or die( "Can't open file!" );
  
$query=    "INSERT INTO files (name, type, size) VALUES(".
            
$DB->quote($name).", ".
            
$DB->quote($type).", ".
            
$DB->quote($size).
            
")";

  
// Execute Query
  
$result = $DB->query($query);
  
$file_id = mysql_insert_id();

// Copy the binary file data to the filedata table in sequential rows each containing MAX_SQL bytes
// Your table should have an index set to auto_increment
// Store the file_id to identify the data fragments
  
while (!feof ($filehandle)) {
      
$data = base64_encode(fread($filehandle,MAX_SQL));
      
$query = "INSERT INTO filedata (file_id, data) VALUES($file_id,\"".$data."\")";
      
$result = $DB->query($query);
   }
  
fclose ($filehandle);
?>

Decode the data fragments and recombine them:
<?php
   $file_id
=$_GET ['file_id'];
  
$query ="select file_id, name, type, size from files where file_id='$file_id'";
  
$result = $DB->query($query);
  
$row= mysql_fetch_array ($result);
  
$type = $row ["type"];
  
$name = $row ["name"];
  
$size = $row ["size"];
  
$file_id = $row ["file_id"];

  
// get the file data
  
$query = "select id, data from filedata where file_id='$file_id' ORDER by id";
  
$result = $DB->query($query);

// decode the fragments and recombine the file
  
$data = "";
   while (
$row = mysql_fetch_array($result)) {
      
$data .= base64_decode($row ["data"]); 
   }
  
// output the file
  
header ("Content-type: $type");
  
header ("Content-length: $size");
  
header ("Content-Disposition: attachment; filename=$name");
  
header ("Content-Description: PHP Generated Data");
   echo
$data;
?>
e4c5 at raditha dot com
12-Aug-2003 09:22
Progress bar support has been a recurring theme in many a PHP mailing list over the years. You can find a free progress monitor component for PHP file uploads at

The advantage of this system is that you do not have to apply any patches to PHP to make use of it.
user at php dot net
26-Jul-2003 07:16
To add an example to the bart at combodata dot nl's note:

When you're using this type of form:

<form name="" method="post" action="dostuff.php" enctype="multipart/form-data" >
<input type="file" name="dat[foto]" />
<input type="file" name="dat[banner]" />
<input type="file" name="dat[pdf]" />
</form>

You can refer to the uploaded files this way:
$_FILES["dat"]["tmp_name"]["foto"]
name: $_FILES["dat"]["name"]["foto"]
size: $_FILES["dat"]["tmp_name"]["foto"]
mitchy_AT_spacemonkeylabs_DOT_com
17-Jun-2003 04:29
After hours of profanity-laced tirades and futility mixed with panic, I have found the solution to my ills:  HTTP_Upload, written by Thomas V.V. Cox, found at:



First, it is done in PEAR[1], and you all should use PEAR too.  Second, it has many additions, like creating unix-friendly filenames from those wacky Windows users (filenames with spaces, yuck!)...

I cut-n-pasted from the example page, and it just plain worked.  No muss, no fuss, no messy applicator brush!

[1]What is PEAR?  It is a means for PHP developers to share and reuse code, usually reducing development costs and efforts by an order of magnitude.  Even more important, someone else figured out that blasted library of functions that have had you stumped for days, and it is wrapped up in a neat, easy-to-use object.  With a simple command-line installer, PEAR makes getting PHP-based add-ons and libraries as easy as apt-get!  It is found at
diegoful at yahoo dot com
25-Mar-2003 08:22
SECURITY CONSIDERATION: If you are saving all uploaded files to a directory accesible with an URL, remember to filter files not only by mime-type (e.g. image/gif), but also by extension. The mime-type is reported by the client, if you trust him, he can upload a php file as an image and then request it, executing malicious code.
I hope I am not giving hackers a good idea anymore than I am giving it to good-intended developers. Cheers.
garyds at miraclemedia dot ca
16-Mar-2003 02:12
As it has been mentioned above, Windows-based servers have trouble with the path to move the uploaded file to when using move_uploaded_file()... this may also be the reason copy() works and not move_uploaded_file(), but of course move_uploaded_file() is a much better method to use. The solution in the aforementioned note said you must use "\\" in the path, but I found "/" works as well. So to get a working path, I used something to the effect of:

"g:/rootdir/default/www/".$_FILES['userfile']['name']

...which worked like a charm.

I am using PHP 4.3.0 on a win2k server.

Hope this helps!
ov at xs4all dot nl
09-Mar-2003 03:08
This took me a few days to find out: when uploading large files with a slow connection to my WIN2K/IIS5/PHP4 server the POST form kept timing out at exactly 5 minutes. All PHP.INI settings were large enough to accomodate huge file uploads. Searched like hell with keywords like "file upload php timeout script" until I realised that I installed PHP as CGI and added that as a keyword. This was the solution:

To set the timeout value:
1. In the Internet Information Services snap-in, select the computer icon and open its property sheets.
2. Under Master Properties, select WWW Service, and then click the Edit button
3. Click the Home Directory tab.
4. Click the Configuration button.
5. Click the Process Options tab, and then type the timeout period in the CGI Script Timeout box.
mccorkle+php at devteam dot org
08-Jan-2003 07:59
To anyone that is trying to use values="foo" to set a default value in a input type of ``file'', I found this out from

*  Internet Explorer, Netscape and Opera do not use the VALUE attribute as the default contents of the input area. Any default value set via HTML is not usable via scripting and the DOM as well (hence it is not listed as 'supported' in any of the browsers.) If a user enters text in the field however, that value is then reachable via the DOM as it normally would be for a normal INPUT field (via the .value property.) The reason for this behavior would presumably be to ensure the security/safety of users against malicious authors.

Tooke me a bit to find this, so I figured I'd share.
panayotis at yellownetroad dot com
18-Dec-2002 11:21
In order to enable $HTTP_RAW_POST_DATA, you can set always_populate_raw_post_data to On either in php.ini or .htaccess
travis dot lewis at amd dot com
04-Dec-2002 08:58
If you we dumb like me you installed Redhat 8.0 and kept the default install of packages for Apache 2.0 and PHP4.2.2.  I could not upload any files larger than 512kB and all the php directorives were set to 32MB or higher.
memory_limit = 128M
post_max_size = 64M
upload_max_filesize = 32M

And my upload web page was set to 32MB as well:
<Form ID="frmAttach" Name="frmAttach" enctype="multipart/form-data" action="attachments.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="33554432" />

However, the insiduous php.conf (/etc/httpd/conf.d/php.conf) file used by default RPM install of Redhat httpd has a LimitRequestBody set to 512kB ("524288" ).  Adjusting this to 32MB ("33554432") got things going for the larger files.  Here is my php.conf file in its entirety.  Hope this helps someone.  L8er.

#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

LoadModule php4_module modules/libphp4.so

#
# Cause the PHP interpreter handle files with a .php extension.
#
<Files *.php>
   SetOutputFilter PHP
   SetInputFilter PHP
   LimitRequestBody 33554432
</Files>

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
solja at gci dot net
04-May-2002 01:11
Just another way I found to keep an uploaded file from overwriting an already exisiting one - I prefix each uploaded file with time() timestamp. Something like:
$unique_id = time();

Then when I give the new name to move the file to, I use something like:
$unique_id."-".$filename

So I get a fairly unique filename each time a file is uploaded. Obviously, if two files are uploaded at once, both will have the same timestamp, but I don't worry too much about that. Hope this might help someone.
am at netactor dot NO_SPAN dot com
15-Mar-2002 06:20
Your binary files may be uploaded incorrectly if you use modules what recode characters. For example, for Russian Apache, you should use
<Files ScriptThatReceivesUploads.php>
CharsetDisable On
</Files>

<XFormsの処理エラーメッセージの説明>
 Last updated: Tue, 21 Dec 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: /
Last updated: Mon Mar 14 08:13:06 2005 Local time zone must be set--see zic manual page