PHP Copying, Creating & Deleting files
Copy file using PHP:- In PHP when we want to copy our file from source to destination then we have to use following syntax.
Syntax:
Bool copy (string $source, string $destination);
Example:
Echo Copy (source.txt,dest.txt);
Create file using PHP:- In PHP when we want to create our file then we will use fopen(). In fopen() we will pass the name of file and also give the permission (read,write to that file). The syntax for fopen is
Syntax
fopen (string $filename, string $ mode);
example:
$fopenexample = fopen($fopenexample, 'w') or die("can't open file");
Delete file using PHP:- In PHP when we want to delete our file then we will use unlink() function. In unlink() we will pass the name of file. The syntax of unlink is
Syntax
unlink (string $filename);
Example:
<?php
$file = "unlink.txt";
if (!unlink($file)){
echo ("Error deleting $file");
}
else
{
echo ("Deleted $file");
}
?>
0 Comment(s)