Welcome Guest, Not a member yet? Register   Sign In
How I can Unlink a file
#1

[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?
#2

[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.
#3

[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 !!!
#4

[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
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB