Tue Jun 23 2020

Create Delete File

PHP Scripting2789 views

File Name: create-delete-file.php

<?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!
Reference:

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