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 8080545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:26:46+00:00 2026-06-05T16:26:46+00:00

I have a script that recursively loops through all the sub directories and compresses

  • 0

I have a script that recursively loops through all the sub directories and compresses all the jpegs. I print the file size, before and after the compression but it prints the same number.
The script I am running is:

set_time_limit (86000);
ob_implicit_flush(true);
$main = "files";

function readDirs($main){
  $dirHandle = opendir($main);
  while($file = readdir($dirHandle)){
    $newFile = $main.'/'.$file;
    if(is_dir($newFile) && $file != '.' && $file != '..'){
       readDirs($newFile);
    }
    else{
        if($file != '.' && $file != '..' && stristr($newFile,'.jpg'))
        {
            //echo $newFile.'</br>';
            $img = imagecreatefromjpeg($newFile);
            echo 'Compressing '.$newFile.'... from ('.filesize($newFile).' bytes) to (';
            imagejpeg($img,$newFile, 30);
            echo filesize($newFile).' bytes)...<br>';
            for($k = 0; $k < 40000; $k++)
                echo ' '; // extra spaces to fill up browser buffer
        }
    }
  } 
}

And the output I get is:

Compressing
files/1013/0079/3180/Beautifully_renovated_garden_apartment_in_Rehavia_7.JPG…
from (58666 bytes) to (58666 bytes)… Compressing
files/1013/0088/0559/Exquisite_stand_alone_house_in_Givat_Hamivtar_exceptional_views_3.JPG…
from (49786 bytes) to (49786 bytes)… Compressing
files/1013/0088/0587/Exquisite_stand_alone_house_in_Givat_Hamivtar_exceptional_views_6.JPG…
from (18994 bytes) to (18994 bytes)… Compressing
files/1013/0138/4914/Beautiful_4_rooms_apartment_with_views_to_the_Old_City_2.JPG…
from (527801 bytes) to (527801 bytes)… Compressing
files/1013/0208/0656/Fevrier_2011_005.JPG… from (35607 bytes) to
(35607 bytes)… Compressing
files/1013/0216/6078/Beautiful_townhouse_in_the_heart_of_the_German_Colony_00.JPG…
from (42509 bytes) to (42509 bytes)… Compressing
files/1013/0217/1359/Unique_luxurious_new_penthouse_in_the_heart_of_the_German_Colony_028.jpg…
from (1101251 bytes) to (1101251 bytes)… Compressing
files/1013/0269/0299/Exclusive_Duplex_Penthouse_in_the_German_Colony_0171.jpg…
from (20912 bytes) to (20912 bytes)… Compressing
files/1013/0821/0299/Beautiful_views_to_the_Knesset_and_Gan_Saker_016.JPG…
from (570428 bytes) to (570428 bytes)… Compressing
files/1013/0822/0660/Beautiful_new_penthouse_in_luxurious_building_with_pool_158double.jpg…
from (1020561 bytes) to (1020561 bytes)… Compressing
files/1013/0847/8190/New_luxurious_penthouse_with_private_entrance_in_Old_Katamon_016.JPG…
from (542071 bytes) to (542071 bytes)… … … …

Can someone tell me what problem is? Why is the size not updating?

Thanks a lot!

  • 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-06-05T16:26:47+00:00Added an answer on June 5, 2026 at 4:26 pm

    filesize() uses a caching mechanism (the “stat cache”) that may not have enough time to refresh in between the two calls.

    Use clearstatcache() to force the cache to refresh.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have script that loops through an array of html tag id's, some elements
I have a script that runs recursively over many directories, and I'd like to
I have script that reads remote file content and writes it to local server.
I have following script that executes all the .reg files in the current directory.
I have a script that uses a ton of redirects. About half way through
I have found a useful shell script that shows all files in a directory
I have a script that scans subdirectories recursively and deletes files older than X
Need to have a Shell script that will * Identify all the files [
I have a python script that recursively walks a specified directory, and checksums each
I have this script that run to fix my menu bar to the browser

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.