I am having trouble with unlink in php… The files in the directory are uploaded with php form.
ls -l of /files/uploads/
total 6976
-rw-r--r-- 1 alex admin 689030 15 Aug 11:40 01805_goneclubbing_1680x1050.jpg
-rwxrwxrwx 1 alex admin 174932 15 Aug 11:52 4vvF60D.tmp.jpg
-rw-r--r-- 1 alex admin 2699554 15 Aug 12:16 example.JPG
php script (cakePHP framework):
$file_path = '/files/uploads/';
$file_name = $file['Upload']['path'];
$classroom_id = $file['Upload']['classroom_id'];
if (unlink($file_path . $file_name)) {
if ($this->Upload->delete($id)) {
$this->setFlash('File deleted');
$this->redirect(array('controller' => 'classrooms', 'action' => 'view', $classroom_id));
}
}
php error:
Warning (2): unlink(/files/uploads/example.JPG) [function.unlink]: No such file or directory [APP/controllers/uploads_controller.php, line 55]
I searched on stackoverflow, tried giving 777 permissions and still not working. I can access the image through the browser at that path.
Thanks for the help!
On any UNIX system,
/is your system root. So when you try to access/files, you try to access a folderfileslocated at your system root. I think you want to access/path_to_www/files, so either use a variable which stores your base path or use a relative path.On the other hand, when you try to access
/filesfrom your web browser, it reaches the/of your web directory (or an alias path). So it is totally normal that you can access your image from your browser but not from php.