Problem: when uploading, variable is empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jvic
Forum Newbie
Posts: 7
Joined: Mon Oct 06, 2003 2:04 pm

Problem: when uploading, variable is empty

Post 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.
jvic
Forum Newbie
Posts: 7
Joined: Mon Oct 06, 2003 2:04 pm

Post by jvic »

Forgot to mention: i've tested with many browsers (under Linux and Windows), always get the same error.

Victor.
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

Try doing this instead:

Code: Select all

<?php
echo($_FILES['arquivo']['name']);
?>
jvic
Forum Newbie
Posts: 7
Joined: Mon Oct 06, 2003 2:04 pm

Post 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.
jvic
Forum Newbie
Posts: 7
Joined: Mon Oct 06, 2003 2:04 pm

Post 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.
Post Reply