<?php $myfile = "./test.txt"; if (file_exists ($myfile)){ $msg="File already exists. "; }else{ $myfile = @fopen ($myfile, "w+") or die ("Couldn't create the file" ); $msg= "File created! " ; fclose ($myfile); } echo "$msg"; ?>