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!