Pop\File\File::move PHP Method

move() public method

Move the file object directly to another location on disk.
public move ( string $new, boolean $overwrite = false ) : File
$new string
$overwrite boolean
return File
    public function move($new, $overwrite = false)
    {
        // Check to see if the new file already exists.
        if (file_exists($new) && !$overwrite) {
            throw new Exception('Error: The file already exists.');
        }
        if (file_exists($this->fullpath)) {
            rename($this->fullpath, $new);
        } else {
            file_put_contents($new, $this->output);
        }
        $this->setFile($new);
        return $this;
    }

Usage Example

Example #1
0
 public function testMoveException()
 {
     $this->setExpectedException('Pop\\File\\Exception');
     $f = new File('access.txt');
     $f->move(__DIR__ . '/../tmp/access.txt');
 }