![]() |
How I can Unlink a file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How I can Unlink a file (/showthread.php?tid=5111) |
How I can Unlink a file - El Forum - 01-06-2008 [eluser]hz[/eluser] Hi I want o delete a file when its particular record is deleted. i've simply use the php unlink function to unlink that file. unlink("images/myimage.jpg"); The code is saved in a php file (htdocs/project/system/application/views/delete.php) my images are saved in a folder placed on root folder(htdocs/project/images). I've tried a lot but its continuosly giving me the error that no such file or directory found. What i m doing wrong? How I can Unlink a file - El Forum - 01-07-2008 [eluser]Dr.Dan[/eluser] Try using getcwd() in path. Also, check the file permission. The files/dir must be writable or owned by the system in order to be deleted. How I can Unlink a file - El Forum - 01-07-2008 [eluser]Sarfaraz Momin[/eluser] well you need to provide the complete of absolute path of the file from the root folder to unlink it and it should work. Code: unlink("/htdocs/project/images/myimage.jpg"); Good Day !!! How I can Unlink a file - El Forum - 01-07-2008 [eluser]hz[/eluser] Thnx every body, but i've found another way. I've created the controller for that delete page. And now its working fine. thank you again. regards, Hasan How I can Unlink a file - El Forum - 01-07-2008 [eluser]Phil Sturgeon[/eluser] Two better options for people in the future, you can use unlink with a relative path from your webroot, for example: Code: unlink("./project/images/myimage.jpg"); That will be alot more portable. Or you can use FTP if you dont want to have lots of writeable directories on your site. I generally will only have ONE temp folder that all files are sent to, then connect to my own server using FTP and move them to a destination folder. |