/** * Asserts an image is of the type claimed. * * @param T_File_Uploaded $file * @param int $type one of the IMAGETYPE_XX constants * @param string $name name to reference image type */ protected function assertType($file, $type, $name) { $msg = "is not a valid {$name} file"; if (function_exists('exif_imagesize')) { if (exif_imagetype($file->__toString()) !== $type) { throw new T_Exception_Filter($msg); } } else { /* slower but more widely available */ $data = getimagesize($file->__toString()); if (!is_array($data)) { throw new T_Exception_Filter($msg); } if ($data[2] !== $type) { throw new T_Exception_Filter($msg); } } }
function testPathSetInConstructor() { $file = new T_File_Uploaded('some/tmp/file', 1024, 'file.notanext'); $this->assertSame('some/tmp/file', $file->__toString()); }