homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

I can't seem to count
php count function

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

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?



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

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


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

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.


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

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


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

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved