php - Check if filename exists and -


i wondered if there way check if filename exists , add number after it, know - in basic possible if once it'll add 1 after it.

but how check if has done more once? first time add 1 2 3 , on?

$title = $_post['title']; $content = $_post['content']; $compile = $title. "\r\n" .$content; $content = $compile; $path = "../data/" .md5($title). ".txt"; $fp = fopen($path,"wb"); fwrite($fp,$content); fclose($fp);  $con=new mysqli("###","###_public","###","###");  if (!($stmt = $con->prepare("insert `blog_posts` (`post_title`,`post_content`,`post_date`) values (?,?,?)")) || !is_object($stmt)) {     die( "error preparing: (" .$con->errno . ") " . $con->error); } $stmt->bind_param('sss', $_post['title'], $path, $_post['date']); if($stmt->execute()) {      echo "successfully posted"; } else {     echo "unsuccessfully posted"; }     $stmt->close(); 

thanks in advance

the general idea this:

$basefilename = "somefile"; $filename = $basefilename; $i = 0; while(file_exists("../data/".$filename.".txt") $filename = $basefilename.(++$i); 

adapt needed.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -