Forum Moderators: coopster

Message Too Old, No Replies

Need Access to Default File Attributes

         

bubone2

7:53 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



When I was first learning php, I created an upload script. The basics of the script had:

<form method="POST" ENCTYPE="multipart/form-data">
<input type="file" name="FILE">
<input type="submit" name="SUBMIT" value="Upload">
</form>

Then in the submit section, it accesses the filename and filesize by virtue of a default php ability to extract these attributes by using: $FILE_name and $FILE_size (where _name gives the name of $FILE and _size gives the size of $FILE).

if($SUBMIT)
echo " Filename: $FILE_name <br> Filesize: $FILE_size";

Also, I did add the necessary lines to handle the post variables, like so:

$FILE = $_POST['FILE'];
$SUBMIT = $_POST['SUBMIT'];

I have tried to mimic this script in a new upload script, but am unable to access those same attributes (_name and _size).

At the time of my original upload script, we were running it on a Linux server (but I don't remember what we were running for a php version). Currently, I am running PHP 4.2.3 on Mac OS 10.2.8 server.

One thought I had was that maybe PHP 4.2.3 no longer supports _name and _size. Or, maybe I am not handling the retrieval of the POST var for the file correctly? I wonder this because I did try print_r($_POST) and I only got the submit returned as a post var.

Any ideas? Thanks,
Josh

[edited by: bubone2 at 8:09 pm (utc) on Dec. 6, 2004]

Birdman

8:00 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I believe you are just using the $_FILES global incorrectly. See this page in the manual:

[us2.php.net...]

bubone2

8:10 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



ah thanks Birdman. I think I was editing my post when you were replying, becuase I was explaining how I was attempting to get the FILE var through $_POST superglobal. I was looking in the wrong place.

And upon viewing the link, I see that it is also handled a little differently as well.

Thanks,
Josh

bubone2

8:27 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



One more for ya ...

I see from the link provided that the name is found in the FILES superglobal as so:

$_FILES['userfile']['name']

But, forgive me if I am being a little slow here ... but how do I access the name of the file so that I can echo it?

Josh

[Edited]: Umm ... nevermind. I got it.
$_FILES['FILE']['name']

[edited by: bubone2 at 8:33 pm (utc) on Dec. 6, 2004]

Birdman

8:33 pm on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should do it for ya:

<?php
if ( isset ( $_FILES['userfile'] ) ) echo $_FILES['userfile']['name'];
?>

bubone2

8:33 pm on Dec 6, 2004 (gmt 0)

10+ Year Member



thanks again