Welcome to WebmasterWorld Guest from 54.226.25.231

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

I can't seem to count

php count function

     

Gibisan

6:00 am on Aug 3, 2006 (gmt 0)

10+ Year Member



I have just moved my site to a new server and my image upload script is failing due to an inability to count the file array.

The upload form code allows a max of four images - the form code for an image looks like
<input name="userfile[]" onchange="return TestFileType(this);" type="file" />

When this form is posted the new script starts by finding how many image files have been uploaded
$tot = count($userfile);

The problem is that $tot is always 0. count() does not seem to be able to count!
I have checked that a file is being uploaded using $_FILES['userfile']['name'][0] and it is.

This worked fine on the old server.
I realise I could just loop though the filename array until I dont find one but I'd rather just leave the script unchanged. Any ideas where the problem lays?

Gibisan

6:15 am on Aug 3, 2006 (gmt 0)

10+ Year Member



Ahh - I think the problem is with register_globals being off. Problem solved.

coopster

12:39 pm on Aug 3, 2006 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Using Register Globals [php.net] was a security meausure addressed quite a few releases back. It is not good practice to continue using them as such. You'll want to read that manual page and address your issue as soon as possible.

Gibisan

2:57 am on Aug 4, 2006 (gmt 0)

10+ Year Member



I did read all about it yesterday before just switching register_globals on. Once I realised the security implications I changed my scripts to use $tot = count($_FILES['userfile']['tmp_name']); as the count and then $_POST['item'][num] throughout.
Bye bye register_globals

coopster

1:59 pm on Aug 4, 2006 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Good for you, that's the best way to handle it. Congrats.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month