delete(unlink) file in directory in PHP

Today, We want to share with you unlink in php.In this post we will show you php delete file in directory, hear for similar to UNIX unlink() Function we will give you demo and example for implement.In this post, we will learn about php delete file Functions with an example.

PHP | unlink() Function

There are the Following The simple About delete uploaded file php Full Information With Example and source code.

As I will cover this Post with live Working example to develop php delete file, so The unlink() function is an inbuilt function in PHP is used for this example is following below.

Syntax:

unlink( $filename, $context )

delete a file named tamilrokers.txt using unlike() function

<?php 

$find_file_folder = "tamilrokers.txt"; 

// Use unlink() function to delete a file 
if (!unlink($find_file_folder)) { 
	echo ("$find_file_folder cannot be deleted due to an error"); 
} 
else { 
	echo ("$find_file_folder has been deleted"); 
} 

?> 

delete a file named tamilrokers.txt using unlike() function

<?php 
$find_file_folder = fopen('tamilrokers.txt', 'w+'); 
	
// writing on a file named tamilrokers.txt 
fwrite($find_file_folder, 'A computer science portal for geeks!'); 
fclose($find_file_folder); 

// Use php unlink() function to delete a file 
if (!unlink($find_file_folder)) { 
	echo ("$find_file_folder cannot be deleted due to an error"); 
} 
else { 
	echo ("$find_file_folder has been deleted"); 
} 

?> 

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Read Also:  SQL SELECT DISTINCT Statement

I hope you get an idea about unlink in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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