Skip to content

Commit f220cd1

Browse files
committed
fixed problem with the example code
1 parent 8a437aa commit f220cd1

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

cookbook/doctrine/file_uploads.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ lifecycle callbacks implemented::
196196
public function preUpload()
197197
{
198198
if ($this->file) {
199-
$this->setPath($this->generatePath($this->file));
199+
// do whatever you want to generate a unique name
200+
$this->setPath(uniq().'.'.$this->file->guessExtension());
200201
}
201202
}
202203

@@ -212,7 +213,7 @@ lifecycle callbacks implemented::
212213
// you must throw an exception here if the file cannot be moved
213214
// so that the entity is not persisted to the database
214215
// which the UploadedFile move() method does
215-
$this->file->move($this->getUploadRootDir(), $this->generatePath($this->file));
216+
$this->file->move($this->getUploadRootDir(), $this->path);
216217

217218
unset($this->file);
218219
}
@@ -226,12 +227,6 @@ lifecycle callbacks implemented::
226227
unlink($file);
227228
}
228229
}
229-
230-
protected function generatePath(UploadedFile $file)
231-
{
232-
// do whatever you want to generate a unique name
233-
return uniq().'.'.$this->file->guessExtension();
234-
}
235230
}
236231

237232
If you want to use the ``id`` as the name of the file, the implementation is

0 commit comments

Comments
 (0)