Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change file size retrieval to use PHP functions as shell exec has nev…
…er worked here because of the douple escapeshellargs
- Loading branch information
1 parent
5b28264
commit 11bcc40
Showing
1 changed file
with
2 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11bcc40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the reason we used shell for getting the filesize is due to limit's on 32 bit vs 64 bit numerals.
Using the shell method, we get back a string which can be parsed regardless of the returned number.
11bcc40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mastacontrola The major issue with this was actually the douple escapeshellarg call. Filenames would ended up as
''/path/filename.ext''
and ended up hashing even all the bigger files too because$filesize
was literally always zero (when called from within thegetHash
function).11bcc40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sebastian-Roth
I noticed the FOGImageSize service makes use of this function, which would explain why the image size on server is reported as 4K since that's the directory size itself.
It seems pretty difficult in PHP to accurately get size of a directory content.
This one may work though:
function dir_size($directory) { $size = 0; foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) { $size += $file->getSize(); } return $size; }
(obviously would need to be altered to work properly)
from https://stackoverflow.com/questions/478121/how-to-get-directory-size-in-php
Then again, I'm not sure if that would then still work for files only. Perhaps we need to check if it's a file or directory and check based on that info, that's not too hard to do.
11bcc40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Quazz Just pushed a commit to hopefully address this: e3b754e
11bcc40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sebastian-Roth Looks good, it's reporting correct sizes for a good number of images, though some report back 0 for some reason. That said, I don't think that's down to this function at this point since it does work in manual tests!
11bcc40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated working-1.6 with a few minor changes.
For example, continuing the loop using the RecursiveIteratorIterator method isDot(). Also, it will default a size based on the path, but if the path is a directory it will do the recursion. Less logic checking = microoptimization, but also easier to follow logic.