The copy() method copies a file to a new location. The method accepts three
parameters: the path to the source file, the path to the destination file, and an
optional base path. If a base path is provided, it will be prepended to the source and
destination paths.
The copy() method returns a Boolean response. This example copies the foo.php
file to the bar.php file in the frontend root of the current component:
if (!JFile::copy('foo.php', 'bar.php', JPATH_COMPONENT))
{
// handle failed file copy
}
The move() method works in the same way, except that it relocates the file rather
than creating a copy of the file. This method returns a Boolean response. This
example moves the file foo.php to the file bar.php in the frontend root of the
current component:
if (!JFile::move('foo.php', 'bar.php', JPATH_COMPONENT))
{
// handle failed file move
}
Chapter 12
[ 353 ]
The last of these management-type methods we'll look at is the delete() method.
This method removes one or more files from the file system.
Pages:
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491