How to check if a file or directory exists using php

Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

How to check if a file or directory exists using php

Post by Neo » Sun Feb 21, 2010 4:05 pm

Code: Select all

<?php 

$filename = '/path/file.txt'; 

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

?> 
Post Reply

Return to “PHP & MySQL”