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 ? 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 How to Convert File Content to Byte Array in PHP ? Converting file content to a byte array in PHP is a useful technique for various applications, including file manipulation, data processing, and when working with binary files like images or PDFs. PHP offers multiple ways to read file content and convert it into a byte array, providing flexibility t 5 min read PHP | ftp_mdtm() Function The ftp_mdtm() function is an inbuilt function in PHP which is used to get time when the file on FTP server was last modified. Syntax:Â ftp_mdtm( $ftp_connection, $file ) Parameter: This function accepts two parameters as mentioned above and described below:Â Â $ftp_connection: It is required paramet 2 min read How to get the input file size in jQuery ? The task is to get the fileSize when a user uploads it using JQuery. Approach: Display the text Choose file from system to get the fileSize on the screen. Click on the browse button to select the upload file. After selecting a file, the function is called which display the size of the selected file. 2 min read How to get the number of lines in a file using PHP? Given a file reference, find the number of lines in this file using PHP. There are a total of 3 approaches to solve this. test.txt: This file is used for testing all the following PHP codes Geeks For Geeks Approach 1: Load the whole file into memory and then use the count() function to return the nu 2 min read C# Program to Estimate the Size of File Using LINQ LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It gives the ability to .NET languages to generate queries to retrieve data from the data source. It removes the mismatch between programming languages and databases and the syntax used to create a query is the same no matt 2 min read Like