PHP Exercises: Get the size of a file
PHP: Exercise-39 with Solution
Write a PHP program to get the size of a file.
Sample Solution: -
PHP Code:
<?php
$myfile = fopen("/home/students/ppp.txt", "w") or die("Unable to open file!");
$txt = "PHP Exercises\n";
fwrite($myfile, $txt);
$txt = "from\n";
fwrite($myfile, $txt);
$txt = "w3resource\n";
fwrite($myfile, $txt);
fclose($myfile);
echo "Size of the file: ".filesize("/home/students/ppp.txt")."\n";
?>
Sample Output:
Size of the file: 30
Flowchart:

PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a PHP program to valid an email address.
Next: Write a PHP program to calculate the mod of two given integers without using any inbuilt modulus operator.
What is the difficulty level of this exercise?
PHP: Tips of the Day
PHP: Anonymous recursive PHP functions
In order for it to work, you need to pass $factorial as a reference
$factorial = function( $n ) use ( &$factorial ) { if( $n == 1 ) return 1; return $factorial( $n - 1 ) * $n; }; print $factorial( 5 );
Ref : https://bit.ly/38dj7jm
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework