Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7675311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:55:59+00:00 2026-05-31T16:55:59+00:00

So for some reason this just doesn’t make sense to me. What Im trying

  • 0

So for some reason this just doesn’t make sense to me.

What Im trying to do is display 1 of 2 things:

  1. If the filesize of just 1 image in the folder is too big, display the error message I have above.
  2. If all of the filesizes are ok, display a bit of HTML code

Also, is my threshold correct if I want the limit to be 5MB?

<?php
$threshold = 5368709120;
$path = 'dir/'.$username;
foreach (glob($path."/{*.gif,*.jpg,*.jpeg,*.png}",GLOB_BRACE|GLOB_NOSORT) as $filename)  
{
    $size = filesize($filename);
    if ($size > $threshold) {
        exit('One or more of your photos are larger than 5MB. Resize your photos and try again.');
    }
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:56:00+00:00Added an answer on May 31, 2026 at 4:56 pm

    No, your file limit is actually 5 gigabytes:

    5 -> bytes = 5
    5 * 1024 -> kilobytes = 5,120
    5 * 1024 * 1024 -> megabytes = 5,242,880
    5 * 1024 * 1024 * 1024 -> gigabytes => 5,368,709,120
    

    For user friendliness, you should tell the user WHICH file is too large, as well as check ALL the files before exiting. Let’s say the user didn’t know there was a 5 meg limit, and uploaded 50 files. 49 are too large. You’re just telling the user there’s a problem, not what caused the problem. Now they have to re-upload a file, then do it again. now there’s 48 files too big, and around they go.

    Something like this would be more appropriate

    $limit = 5 * 1024 * 1024; // 5 meg
    $errors = array();
    
    foreach (glob($path."/{*.gif,*.jpg,*.jpeg,*.png}",GLOB_BRACE|GLOB_NOSORT) as $filename)  
       if (filesize($filename) > $limit) {
          $errors[] = $filename
       }
    }
    
    if (count($errors) > 0) {
       echo "The following files are too large: <ul>";
       echo implode("</li><li>", $errors);
       echo "</ul>";
    } else {
       echo "Everything A-OK!";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get this working but for some reason it's just not right.
An easy problem, but for some reason I just can't figure this out today.
For Some reason this query doesn't work in SSIS Select IDLOGARCHIVOS, NOMBREARCHIVO, FECHACREACION from
for some reason this code wont work, it doesn't seem to read the javascript.php
I know this has been asked before but for some reason that strategy doesn't
For some reason this just isn't inserting into my database... HTML <form name=testimonials_form method=post
For some reason this program is saying that 'switch' is not defined. What is
For some reason This php script won't echo anything: <?php setcookie(pop,'hi',time()+604800); echo $HTTP_COOKIE_VARS['pop']; ?>
For some reason this function confused me: def protocol(port): return port == 443 and
For some reason this only returns the name of the first item in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.