Create Delete File

<?php
	/* Create new file */
	$filename = "myFile.txt";
	
	/* Open file in write mode */
	$file = fopen($filename, "w") or die("Unable to open file!");
	$txt = "My first file!";
	
	/* Write text into file */
	fwrite($file, $txt);
	
	/* Close file */
	fclose($file);
	echo "File created successfully!<br />";
	
	
	/* Delete file */
	/* Checking is file exist or not */
	if(is_file($filename)) {
		
		/* Unlink(delete) file */
		if(unlink($filename))
			echo "File deleted successfully!";
		else
			echo "File can't be delete...try again!";
	}
	else
		echo "File no found!";
?>



/* Output */
File created successfully!

File deleted successfully!

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!