bryanptcs Posted December 19, 2006 Share Posted December 19, 2006 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 More sharing options...
AV1611 Posted December 19, 2006 Share Posted December 19, 2006 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} Link to comment https://forums.phpfreaks.com/topic/31259-adding-s-from-an-array-together/#findComment-144624 Share on other sites More sharing options...
thepip3r Posted December 19, 2006 Share Posted December 19, 2006 or just loop through the array to do the addition:[code=php:0] foreach($_FILES['file'] as $file_size) { $total = $total + $file_size;}if ($total > $max) { blah blah}[/code] Link to comment https://forums.phpfreaks.com/topic/31259-adding-s-from-an-array-together/#findComment-144659 Share on other sites More sharing options...
Orio Posted December 19, 2006 Share Posted December 19, 2006 [code]<?php$total = 0;foreach($_FILES['file']['size'] as $size) $total += $size;if($total > $max_size) die("Too much...");?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31259-adding-s-from-an-array-together/#findComment-144666 Share on other sites More sharing options...
AV1611 Posted December 19, 2006 Share Posted December 19, 2006 Which are the really smart, cool ways to do my simple answer LOL ;D Link to comment https://forums.phpfreaks.com/topic/31259-adding-s-from-an-array-together/#findComment-144680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.