Home Tutorials IT Jobs Source Codes Certifications Discussion Forum
  PHP Tutorials
PHP Introduction
PHP Installation
Syntax
Variables
Echo
Strings
Operators
Comments
Require
Include
If...Else
Switch
Forms
Functions
Arrays
While Loop
For Loop
For Each
Do While
Post & Get
File Create
File Open
File Close
File Write / Read
File Delete
File Append
File Truncate
File upload
PHP str replace
PHP substr_replace
PHP Capitalization
PHP Explode
PHP Implode
   IT Jobs
Software Jobs
Networking Jobs
   Model Question Papers
BE Computer Science
MCA
BCA
Others
 
   

PHP - File Delete

PHP - File Unlink

When you view the contents of a directory you can see all the files that exist in that directory because the operating system or application that you are using displays a list of filenames. You can think of these filenames as links that join the files to the directory you are currently viewing.

If you unlink a file, you are effectively causing the system to forget about it or delete it!

Before you can delete (unlink) a file, you must first be sure that it is not open in your program. Use the fclose function to close down an open file.

PHP - Unlink Function

PHP Code:
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fclose($fh);

Now to delete testFile.txt we simply run a PHP script that is located in the same directory. Unlink just needs to know the name of the file to start working its destructive magic.

PHP Code:
$myFile = "testFile.txt";
unlink($myFile);
 

<< Previous | Next >>
Home  |  About us  | Privacy  |  Disclaimer  |  Contact us |  Advertise with us | Our Link Partners
All Rights Reserved 2009, CodeTeller.com