The below code allows me to delete files SOMETIMES. I have checked permissions on the files and folders and they exist and are given proper access. Sometimes when I press the remove button; it removes the file and sometimes it simply refreshes the page and nothing happens. Is there anything I can do to make unlink work correctly? Am I missing something in the code below? This is in 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');
}