Page 1 of 1

Problem: when uploading, variable is empty

Posted: Mon Oct 06, 2003 2:04 pm
by jvic
I've got a problem when uploading files, hope somebody can help me (please). Here's the thing:

I made a PHP/HTML for uploading file, and it's sorta like this:

Code: Select all

<form name=anexar action=anexar_arquivo2.php enctype="multipart/form-data" method=post onSubmit=return(validar(this));>
<input type=hidden name='MAX_FILE_SIZE' value='30000'> 

<input type=file name=arquivo class=text>

<input type=submit value='Ok' class=text>
Well, when i "upload", the variable $arquivo (which should correspond to the input 'arquivo' described above) is empty. In PHP, when i do (right after the "upload"):

Code: Select all

echo($arquivo);
I get the value 'none'. When i do:

Code: Select all

echo($_FILES&#1111;'userfile']&#1111;'name']);
or:

Code: Select all

echo($HTTP_POST_FILES&#1111;'userfile']&#1111;'name']);
I get nothing (blank).

Please, this is driving me nuts... any help is much appreciated.

Thanks,
Victor.

Posted: Mon Oct 06, 2003 2:11 pm
by jvic
Forgot to mention: i've tested with many browsers (under Linux and Windows), always get the same error.

Victor.

Posted: Mon Oct 06, 2003 2:25 pm
by Stoneguard
Try doing this instead:

Code: Select all

<?php
echo($_FILES['arquivo']['name']);
?>

Posted: Mon Oct 06, 2003 2:46 pm
by jvic
OMG, you did it. Thank you!

The upload is still not working, but at least now the variable is alright. I'm doing some maintainance in a code, so i'm trying to figure out what's going on with this code...

The problem now seems to be that the file is not being *really* uploaded. In the code there's a line like this:

Code: Select all

if (file_exists($dest)) &#123;
  // do stuff
&#125;
else &#123;
 // error
&#125;
And that's causing the error. That is, the file_exists is returning false. I've checked the $dest directory, and indeed there is no file uploaded there...

Victor.

Posted: Mon Oct 06, 2003 3:03 pm
by jvic
Ok, i solved the problem! Just in case somebody goes through this too:

The thing is i should use $_FILES['arquivo']['tmp_name'] instead of $FILES['arquivo']['name'].

Now i've got another sort of problem (geez!), but i'm gonna post it in another thread...

Victor.