Question

I wanted to check space available on the storage, where I'm storing users' attachments. I went with disk_free_space() and disk_total_space(). The result is:

Free space: 5.47 GB
Total space: 5.86 GB

So the space occupied = 0.39 GB.

I also looped through the files to catch their size with filesize(). In total the files occupy 18.34 GB. (The maximum file size is 4 MB, so the note in the PHP manual regarding 2GB does note apply)

So:

Total space - Free space != Occupied space

Why?

The filesystem is on HP-UX. I measured all all the values using the same account - I ran all the command from a php script, by executing the script with an internet browser.

I also checked the functions in Windows. The results were OK.

I went through some other questions related to the functions ( How to get the disk space on a server?, How to determin how much space is freeon your server? (php), How to detect the server space enough for the uploaded file or no?, How to get the disk space on a server?, Is it possible to get special Local Disk information from PHP?, php disk_total_space), but did not find an answer.

Was it helpful?

Solution

Depending on the OS and the used filesystem this highly depends on the directory you call the functions with. The reason is, that linux mounts several drives into one big tree. You cannot just call disk_total_space('/'), because this only gives you the size of the root partition. Try disk_total_space($attachmentFolder);.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top