diff --git a/cookbook/doctrine/file_uploads.rst b/cookbook/doctrine/file_uploads.rst index 47d51bde2f1..b7717e605d4 100644 --- a/cookbook/doctrine/file_uploads.rst +++ b/cookbook/doctrine/file_uploads.rst @@ -48,15 +48,26 @@ First, create a simple Doctrine Entity class to work with:: */ public $path; - public function getFullPath() + public function getAbsolutePath() { return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path; } + public function getWebPath() + { + return null === $this->path ? null : $this->getUploadDir().'/'.$this->path; + } + protected function getUploadRootDir() { // the absolute directory path where uploaded documents should be saved - return __DIR__.'/../../../../web/uploads/documents'; + return __DIR__.'/../../../../web/'.$this->getUploadDir(); + } + + protected function getUploadDir() + { + // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view. + return 'uploads/documents'; } } @@ -274,7 +285,7 @@ Next, refactor the ``Document`` class to take advantage of these callbacks:: */ public function removeUpload() { - if ($file = $this->getFullPath()) { + if ($file = $this->getAbsolutePath()) { unlink($file); } } @@ -331,7 +342,7 @@ property, instead of the actual filename:: */ public function removeUpload() { - if ($file = $this->getFullPath()) { + if ($file = $this->getAbsolutePath()) { unlink($file); } }