发布于 2013-11-15 14:33:22
你们都是对的我对实体中的代码做了var转储..。
/**
* @ORM\PostRemove
*/
public function removeUpload()
{
if(file_exists($file)) {
if ($file = $this->getAbsolutePath()) {
unlink($file);
}
}
}
如果文件存在,$file将显示一个空变量。在上传过程中,它将变量保存为$logo
我将代码更改为
/**
* @ORM\PostRemove
*/
public function removeUpload() {
// ** Original Code used file but logo has the name in it.
if(file_exists($this->getAbsolutePath())) {
if ($this->getUploadRootDir() . $this->logo = $this->getAbsolutePath()) {
unlink($this->logo);
}
}
}
它现在正确地删除了该文件。谢谢你们俩。
发布于 2013-11-15 12:53:21
在删除操作中,必须手动删除文件。我假设您将把文件路径存储在数据库中,所以这应该比较容易。
$path = ....//query db to get the path to the file
if($path){
unlink($path);
}
//now you can delete the record in the database
删除文件请参见php文档
发布于 2013-11-15 14:22:48
您可能正在搜索的是Doctrine2生命周期。只需向实体添加一个方法:
/**
* @ORM\PreRemove
*/
public function deleteImage()
{
// unlink your image and what not.
}
还不要忘记实体类的@ORM\HasLifecycleCallbacks()
注释。
https://stackoverflow.com/questions/20010076
复制相似问题