PHP file_exists(), filesize() and realpath() functions

PHP file_exists(), filesize() and realpath() file handling

In this php tutorial we will learn how use file_exists() function, filesize() function and realpath() function with php example.

PHP File handling functions :

  • file_exists() – used to check whether the file exists or not.
  • filesize() – used to check size of file.
  • realpath() – used to check real path of file.

PHP file_exists() Function

The file_exists() function is used to check whether the file or directory exists or not.

file_exists() function syntax

<?php

file_exists(“filename”);

// for check directory
file_exists(“directory name”);

?>

file_exists() function example

In above php file_exists() example if the file ‘abc.txt’ is exists then display message like ‘file available’ other wise display message ‘file not available’.


PHP filesize() Function

The filesize() function is used to check file size.

filesize() function syntax

<?php

filesize(“filename”);

?>

filesize() function example


PHP realpath() Function

The realpath() function is used to check real path of file.

realpath() function syntax

<?php

realpath(“filename”);

?>

realpath() function example

The output of php example:

C:\wamp\www\abc.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 1 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">