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.

Read Also:  Mysql update query statement with example

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:  laravel join Multiple Tables using Model Example

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Send HTML Email File Attachment Using PHPs mail
  2. Read Also:  Google Like Autosuggest Search Using PHP Ajax
  3. Read Also:  PHP Laravel delete files from Public Folder
  4. Read Also:  PHP Remove File from Folder and Database
  5. Read Also:  delete image from folder in php and MySQL Database
  6. Read Also:  Laravel whereRaw havingRaw and orderByRaw Example
  7. Read Also:  PHP Get Query String Parameters using Laravel
  8. Read Also:  laravel findOrFail Eloquent Query
  9. Read Also:  Laravel 5.7 Stripe Payment Gateway Example From Scratch
  10. Read Also:  WordPress Remove Yellow BGBOX - donate