Jump to content

adding #'s from an array together....


bryanptcs

Recommended Posts

I have a script that checks file size to make sure each file is under 50kb when they upload.

the way my form is, it puts the file size into an array...me being dumb and having no idea how to pull it out of an array used implode()

however, that just adds the 2 numbers next to each other eg. 1 file is 50 bytes the other 100...the output of implode()50100.

Is there a function that will actually take the numbers individually through my check file_size code as below:

[code]
$max_size = "500000"; // 50000 is the same as 50kb
$print_size = ($max_size/1000)."kb";
// Check File Size
$file_size = $_FILES['file']['size'];
if ($ok == "1") {
if(implode($file_size) > $max_size)
{
print "<font color='#FF0000'>Error:</font> One of your files is too large.  It must be ".$print_size." or less.";
print "<br><br><a href='procedures.html'>back</a>";
exit;
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31259-adding-s-from-an-array-together/
Share on other sites

I know this is overly simple, (because I'm not smart enough to have a non-simple answer) but if I understand you have an array with info on a group of files.

why don't you just count how many items in they array, the add them up by calling them individually?

if the array has 4 entries

$tot=$arr[0][size]+$arr[1][size]+$arr[2][size]+$arr[3][size];

if ($tot>50000)
{error}
else
{doit}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.