Pop\File\File::delete PHP Method

delete() public method

Delete the file object directly from disk.
public delete ( ) : void
return void
    public function delete()
    {
        // Check to make sure the file exists.
        if (file_exists($this->fullpath)) {
            unlink($this->fullpath);
            // Reset file object properties.
            $props = get_class_vars(get_class($this));
            foreach (array_keys($props) as $key) {
                $this->{$key} = null;
            }
        }
    }

Usage Example

Example #1
0
 public function testWriteSaveAndDelete()
 {
     if (file_exists(__DIR__ . '/../tmp/file.txt')) {
         unlink(__DIR__ . '/../tmp/file.txt');
     }
     $f = new File(__DIR__ . '/../tmp/file.txt');
     $f->write('123')->write('456', true)->save();
     $f->setPermissions(0777);
     $this->fileExists(__DIR__ . '/../tmp/file.txt');
     $this->assertEquals('123456', $f->read());
     $this->assertEquals(6, $f->getSize());
     $this->assertEquals('text/plain', $f->getMime());
     $f->delete();
     $this->assertFalse(file_exists(__DIR__ . '/../tmp/file.txt'));
 }