Re: $_FILES and copy
| From: | Nicole Amashta | Date: | Mon, 11 Feb 2002 16:39:25 +0000 |
| Subject: | Re: $_FILES and copy | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-11964@lists.php.net to get a copy of this message | ||
You need to include in the input tag the enctype attribute like so:
<input type=file name=uploadfile size=30 enctype="multipart/form-data">
Also, make sure the temporary directory is set in your php.ini (by default,
\tmp is set in php.ini. You need to create a directory for temporary files
and set the path in php.ini. This is where files are temporarily copied to
when doing uploads, etc. The file is renamed with some temp name and then
you have to specify the name the file will be called when you put it on the
server from the client.
Here's a function you can use:
<snip>
function upload($source,$destination,$overwrite=false)
{
# $source is the value passed from the form, in your case $uploadfile
# $destnation will be the path to where the file will be copied to plus
the file name
# $overwrite is a flag that will check to make sure file exists before
overwriting if set to false
if ( !file_exists($source) ) return false;
if ( !$overwrite && file_exists($destination) ) return false;
return copy($source,$destination);
}
$success = upload( $uploadfile, "$path_to_upload_dir/" .
$_FILES["uploadfile"] ["name"], true); ## or false if disallow overwrite
</snip>
Hope this helps some.
Nicole Amashta
www.aeontrek.com
===============================
"Bob Pardoe" <bob.pardoe@hayslogistics.co.uk> wrote in message
news:20020208212007.67373.qmail@pb1.pair.com...
> I am trying to copy a file from the client machine via the browser (IE6)
to
> the server using v4.1.1. with register_globals off
>
> Using <input type=file name=uploadfile size=30>
>
> The user enters c:\Dir1\Dir2\FileName.txt
>
> in php after posting the start page I get
>
> $_FILES["uploadfile"] ["name"] = FileName.txt
> $_FILES["uploadfile"] ["size"] =30k
>
> when I try to execute
>
> copy($_FILES["uploadfile"] ["name"], server_save_location)
>
> it fails saying the file cannot be found.
>
> If I change register_globals to be on and perform
>
> copy($uploadfile, server_save_location) it works fine
>
> I logged this as a bug but was told it was bogus, as the file name was
> returned correctly by $_FILES
>
> Can anyone help please
>
> BOb
>
>
>
>
>