public function generateImageFilename(sfValidatedFile $file)
 {
     return 'rank_' . $this->id . $file->getExtension($file->getOriginalExtension());
 }
示例#2
0
    $t->fail('->save() throws an Exception if you don\'t give a filename and the path is empty');
} catch (Exception $e) {
    $t->pass('->save() throws an Exception if you don\'t give a filename and the path is empty');
}
try {
    $f->save($tmpDir . '/test.txt/test1.txt');
    $t->fail('->save() throws an Exception if the directory already exists and is not a directory');
} catch (Exception $e) {
    $t->pass('->save() throws an Exception if the directory already exists and is not a directory');
}
// ->getExtension()
$t->diag('->getExtension()');
$f = new sfValidatedFile('test.txt', 'text/plain', $tmpDir . '/test.txt', strlen($content));
$t->is($f->getExtension(), '.txt', '->getExtension() returns file extension based on the content type');
$f = new sfValidatedFile('test.txt', 'image/x-png', $tmpDir . '/test.txt', strlen($content));
$t->is($f->getExtension(), '.png', '->getExtension() returns file extension based on the content type');
$f = new sfValidatedFile('test.txt', 'very/specific', $tmpDir . '/test.txt', strlen($content));
$t->is($f->getExtension(), '', '->getExtension() returns an empty string if it does not know the content type');
$f = new sfValidatedFile('test.txt', '', $tmpDir . '/test.txt', strlen($content));
$t->is($f->getExtension(), '', '->getExtension() returns an empty string if the content type is empty');
$t->is($f->getExtension('bin'), 'bin', '->getExtension() takes a default extension as its first argument');
// ->getOriginalExtension()
$t->diag('->getOriginalExtension()');
$f = new sfValidatedFile('test.txt', 'text/plain', $tmpDir . '/test.txt', strlen($content));
$t->is($f->getOriginalExtension(), '.txt', '->getOriginalExtension() returns the extension based on the uploaded file name');
$f = new sfValidatedFile('test', 'text/plain', $tmpDir . '/test.txt', strlen($content));
$t->is($f->getOriginalExtension(), '', '->getOriginalExtension() returns an empty extension if the uploaded file name has no extension');
$t->is($f->getOriginalExtension('bin'), 'bin', '->getOriginalExtension() takes a default extension as its first argument');
unlink($tmpDir . '/test.txt');
sfToolkit::clearDirectory($tmpDir . '/foo');
rmdir($tmpDir . '/foo');
示例#3
0
 public function generateImage3Filename(sfValidatedFile $file)
 {
     return "image3" . $file->getExtension();
 }