下面的代码允许我有时删除文件。我已经检查了文件和文件夹的权限,它们存在并获得了适当的访问权限。有时当我按下删除按钮时;它会删除文件,有时它只是刷新页面而没有任何反应。我可以做些什么来使 unlink 正常工作吗?我在下面的代码中遗漏了什么吗?这是在 ZEND 中。
public function delimageAction()
{
$request = $this->getRequest();
if ($request->isPost()) {
// Get the image name
$imageName = $request->getParam('file');
$old = getcwd();
chdir(APPLICATION_PATH . "/../public/images/blog/"); // Change directory to the files
fclose(APPLICATION_PATH . "/../public/images/blog/" . $imageName);
// Delete it
unlink(APPLICATION_PATH . "/../public/images/blog/" . $imageName)
chdir($old); // Return to old directory
}
$this->_helper->redirector('blog', 'index');
}