How to get the file size using PHP ? Last Updated : 22 Jan, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we are going to discuss how to get the file size using PHP. PHP is a general-purpose scripting language that is suited for both server and client scripting language for website development. To get the file size, we will use filesize() function. The filesize() function returns the size of a file in bytes. This function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure. Syntax: filesize($filename) Parameters: The filesize() function in PHP accepts only one parameter i.e. $filename that specifies the filename of the file whose size that you want to check. Example 1: In this example, we use filesize() function with a file parameter and it returns the size of given file. PHP <?php echo "The File size is: "; echo filesize("gfg.txt"); ?> Output: The File size is: 15 Example 2: In this example, we use filesize() function with a non-existing file parameter then it returns an error message. PHP <?php echo "The File size is: "; echo filesize("gfg2.txt"); ?> Output: The File size is: Warning: filesize(): stat failed for inde1x.php in C:\xampp\htdocs\gfg.php on line 4 Comment More infoAdvertise with us Next Article How to get the file size using PHP ? C chetanjha888 Follow Improve Article Tags : Technical Scripter Web Technologies PHP PHP Programs Technical Scripter 2020 PHP-Misc +2 More Similar Reads How to get the current file name using PHP script ? In this article, we will learn how to get the current filename using PHP. Input : c:/xampp/htdocs/project/home.php Output : project/home.php Input : c:/xampp/htdocs/project/abc.txt Output : project/abc.txt Sometimes, we need to get the current file name with the directory name in which our page is s 2 min read How to count files in a directory using PHP? PHP contains many functions like count(), iterator_count(), glob(), openddir(), readdir(), scandir() and FilesystemIterator() to count number of files in a directory.count() Function: The count() functions is an array function which is used to count all elements in an array or something in an object 3 min read How to get String Length in PHP ? In this article, we learn how to find the length of the string in PHP. Approach: This task can be done by using the built-in function strlen() in PHP. This method is used to return the length of the string. It returns a numeric value that represents the length of the given string. Syntax: strlen($st 1 min read How to Resize JPEG Image in PHP ? Why do we need to resize images? In a website, often, we need to scale an image to fit a particular section. Sometimes, it becomes necessary to scale down any image of random size to fit a cover photo section or profile picture section. Also, we need to show a thumbnail of a bigger image. In those c 2 min read How to find number of characters in a string in PHP ? We have given a string and the task is to count number of characters in a string str in PHP. In order to do this task, we have the following methods in PHP:Table of ContentMethod 1: Using strlen() MethodMethod 2: Using mb_strlen() MethodMethod 3: Using iconv_strlen() MethodMethod 4: Using grapheme_s 3 min read Like