php check if file exists if not create

php check if file exists if not create

Many times we got requirement of check file from specific directory. PHP tutorial for, php check if file exists if not create. Following code will work in all the system like (Mac, Linux and Windows). we given code snippet for checking file exists or not.

php check if file exists if not create
php check if file exists if not create

Using following php code you can check file is present or not in specific directory.


<?php
 $filename = '/var/www/html/test/test.txt';

 if (file_exists($filename)) {
 echo "The file $filename exists";
 } else {
 echo "The file $filename does not exist";
 }

?>

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.