Re: File upload on win2k
| From: | Daniel Gustafsson | Date: | Wed, 18 Oct 2000 12:55:20 +0000 |
| Subject: | Re: File upload on win2k | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-3339@lists.php.net to get a copy of this message | ||
At 13:52 2000-10-18 +0200, you wrote:
>Im hitting a brick wall here. how exactly do i get file upload to work on
>win2k.
>
>i have the upload_tmp_dir = c:\temp in the php.ini But all i get when i try
>and look at the $userfile is
>
>//php2 where the 2 is comeing from i have no idea. i looked all over my
>harddrive looking for a directory called php2 and cant find one.
Ah, now this is the thing.. the name you get in $userfile is the name of the
temporary file, the number is there to avoid problems with multiple users
uploading the same time (or something like that, you probably get the picture)
I personally have the upload_tmp_dir commented out, since that should make it
use the standard windows temporary directory (see TEMP and TMP enviroment
variables)
The filename you get in $userfile is the name of the temporary file, that is
removed as soon as your upload script (the one that the form has as the action
url) is finished, so you need to copy that to the location that you want it in.
This is an extract directly from the PHP manual
---8<---
Example 18-1. File Upload Form
<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>
The _URL_ should point to a PHP file. The MAX_FILE_SIZE hidden field must
precede the file input field
and its value is the maximum filesize accepted. The value is in bytes. In this
destination file, the following
variables will be defined upon a successful upload:
$userfile - The temporary filename in which the uploaded file was stored on
the server machine.
$userfile_name - The original name of the file on the senders system.
$userfile_size - The size of the uploaded file in bytes.
$userfile_type - The mime type of the file if the browser provided this
information. An example would be
"image/gif".
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".
Files will by default be stored in the servers default temporary directory.
This can be changed by setting the
environment variable TMPDIR in the environment in which PHP runs. Setting it
using putenv() from within
a PHP script will not work.
The PHP script which receives the uploaded file should implement whatever logic
is necessary for
determining what should be done with the uploaded file. You can for example use
the $file_size variable to
throw away any files that are either too small or too big. You could use the
$file_type variable to throw away
any files that didnt match a certain type criteria. Whatever the logic, you
should either delete the file from
the temporary directory or move it elsewhere.
The file will be deleted from the temporary directory at the end of the request
if it has not been moved away
or renamed.
---8<---