This is how to check if file exists on server. This is useful when you are creating new files, for example,  PDF files, or uploading files to the server to prevent the unseen and unexpected over-writing of old files.

 

</pre>
//Name of the file to test
$filename = "MyOldImage.jpg";

//Full path to the file in Public folder
$file = "data/images/".$filename;

//Delete old file
if (is_file($file))
{ //if file exists on server; do this
unlink($file); // for example, delete it
}
<pre>

 

Leave a Reply

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