move_uploaded_file on localhost

move_uploaded_file on localhost

am 08.04.2008 22:21:18 von groupie

Hi,
The code below is working - it returns the 'Received' message, however
I cannot find the uploaded file in the destination folder, or anywhere
else (other than source directory). I'm running PHP 5.2.5 on my PC
running Apache 2.0. Thanks.

$uploadDir = "/uploads";
$temp = $uploadDir;

if(is_uploaded_file($_FILES['upfile']['tmp_name']))
{
}
else
{
echo "the file was not uploaded correctly, try again";
exit(0);
}

if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $uploadDir ))
print "Received {$_FILES['upfile']['name']} - its size is
{$_FILES['upfile']['size']}";
else
{
echo "error moving file from ".$_FILES["upfile"]["tmp_name"]." to
$uploadDir";
exit(0);
}
?>

Re: move_uploaded_file on localhost

am 08.04.2008 22:37:09 von piotr

groupie wrote:
> Hi,
> The code below is working - it returns the 'Received' message, however
> I cannot find the uploaded file in the destination folder, or anywhere
> else (other than source directory). I'm running PHP 5.2.5 on my PC
> running Apache 2.0. Thanks.
>
> > $uploadDir = "/uploads";
> $temp = $uploadDir;
>
> if(is_uploaded_file($_FILES['upfile']['tmp_name']))
> {
> }
> else
> {
> echo "the file was not uploaded correctly, try again";
> exit(0);
> }
>
> if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $uploadDir ))
> print "Received {$_FILES['upfile']['name']} - its size is
> {$_FILES['upfile']['size']}";
> else
> {
> echo "error moving file from ".$_FILES["upfile"]["tmp_name"]." to
> $uploadDir";
> exit(0);
> }
> ?>

You should find your file in your root directory, it will be named
'uploads'.

To solve your problem, you should add a filename to the destination
part, like:
move_uploaded_file($_FILES["upfile"]["tmp_name"],
$uploadDir.$_FILES["upfile"]["name"] );

best regards
Piotr Nastaly

Re: move_uploaded_file on localhost

am 08.04.2008 22:38:13 von piotr

Piotr wrote:
> groupie wrote:
>> Hi,
>> The code below is working - it returns the 'Received' message, however
>> I cannot find the uploaded file in the destination folder, or anywhere
>> else (other than source directory). I'm running PHP 5.2.5 on my PC
>> running Apache 2.0. Thanks.
>>
>> >> $uploadDir = "/uploads";
>> $temp = $uploadDir;
>>
>> if(is_uploaded_file($_FILES['upfile']['tmp_name']))
>> {
>> }
>> else
>> {
>> echo "the file was not uploaded correctly, try again";
>> exit(0);
>> }
>>
>> if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $uploadDir ))
>> print "Received {$_FILES['upfile']['name']} - its size is
>> {$_FILES['upfile']['size']}";
>> else
>> {
>> echo "error moving file from ".$_FILES["upfile"]["tmp_name"]." to
>> $uploadDir";
>> exit(0);
>> }
>> ?>
>
> You should find your file in your root directory, it will be named
> 'uploads'.
>
> To solve your problem, you should add a filename to the destination
> part, like:
> move_uploaded_file($_FILES["upfile"]["tmp_name"],
> $uploadDir.$_FILES["upfile"]["name"] );
>
> best regards
> Piotr Nastaly
Ofc, i forgot to add directory separator
move_uploaded_file($_FILES["upfile"]["tmp_name"],
$uploadDir . DIRECTORY_SEPARATOR . $_FILES["upfile"]["name"] );

Re: move_uploaded_file on localhost

am 08.04.2008 23:18:54 von groupie

On Apr 8, 9:38=A0pm, Piotr wrote:
> Piotr wrote:
> > groupie wrote:
> >> Hi,
> >> The code below is working - it returns the 'Received' message, however
> >> I cannot find the uploaded file in the destination folder, or anywhere
> >> else (other than source directory). I'm running PHP 5.2.5 on my PC
> >> running Apache 2.0. Thanks.
>
> >> > >> =A0 $uploadDir =3D "/uploads";
> >> =A0 $temp =3D $uploadDir;
>
> >> if(is_uploaded_file($_FILES['upfile']['tmp_name']))
> >> {
> >> }
> >> else
> >> {
> >> =A0 =A0echo "the file was not uploaded correctly, try again";
> >> =A0 =A0exit(0);
> >> }
>
> >> if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $uploadDir ))
> >> =A0 =A0 =A0 =A0 print "Received {$_FILES['upfile']['name']} - its size =
is
> >> {$_FILES['upfile']['size']}";
> >> else
> >> {
> >> =A0 =A0echo "error moving file from ".$_FILES["upfile"]["tmp_name"]." t=
o
> >> $uploadDir";
> >> =A0 =A0exit(0);
> >> }
> >> ?>
>
> > You should find your file in your root directory, it will be named
> > 'uploads'.
>
> > To solve your problem, you should add a filename to the destination
> > part, like:
> > move_uploaded_file($_FILES["upfile"]["tmp_name"],
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0$uploadDir.$_FILES["upfile"]["nam=
e"] );
>
> > best regards
> > Piotr Nastaly
>
> Ofc, i forgot to add directory separator
> move_uploaded_file($_FILES["upfile"]["tmp_name"],
> =A0 =A0 =A0 =A0 $uploadDir . DIRECTORY_SEPARATOR . $_FILES["upfile"]["name=
"] );- Hide quoted text -
>
> - Show quoted text -

Thank-you! It's working fine now.