Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a97bf67

Browse files
committed
Merge pull request symfony#558 from tristanbes/master
Changed the name of the method to be more revelent. Fix the leading slash on the getWebLocation() for portability
2 parents 770127b + 6d92dd6 commit a97bf67

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

cookbook/doctrine/file_uploads.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,26 @@ First, create a simple Doctrine Entity class to work with::
4949
*/
5050
public $path;
5151

52-
public function getFullPath()
52+
public function getAbsolutePath()
5353
{
5454
return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path;
5555
}
5656

57+
public function getWebPath()
58+
{
59+
return null === $this->path ? null : $this->getUploadDir().'/'.$this->path;
60+
}
61+
5762
protected function getUploadRootDir()
5863
{
5964
// the absolute directory path where uploaded documents should be saved
60-
return __DIR__.'/../../../../web/uploads/documents';
65+
return __DIR__.'/../../../../web/'.$this->getUploadDir();
66+
}
67+
68+
protected function getUploadDir()
69+
{
70+
// get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
71+
return 'uploads/documents';
6172
}
6273
}
6374

@@ -275,7 +286,7 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
275286
*/
276287
public function removeUpload()
277288
{
278-
if ($file = $this->getFullPath()) {
289+
if ($file = $this->getAbsolutePath()) {
279290
unlink($file);
280291
}
281292
}
@@ -332,7 +343,7 @@ property, instead of the actual filename::
332343
*/
333344
public function removeUpload()
334345
{
335-
if ($file = $this->getFullPath()) {
346+
if ($file = $this->getAbsolutePath()) {
336347
unlink($file);
337348
}
338349
}

0 commit comments

Comments
 (0)