Unlink File in Codeigniter

You can delete files from the server with PHP’s file system function unlink() which will delete or remove the files. It can remove all type of files like images, document, media files .. etc.It will return TRUE on success or FALSE on failure.If there is a problem, it is most likely because you do not have permission to delete the file.The directory must be writable by the user in order to remove the file.File not required write permissions.

I am gonna use is_readable() function which tells whether a file exists and is readable or not, It is better to check before attempting to delete action.

For example, if you want to delete files from upload folder(which is located at web server root folder).

That’s it.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Subscribe
Notify of
guest
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
blacmoon
blacmoon
5 years ago

Thanks arjun 🙂

arjun
5 years ago
Reply to  blacmoon

You are welcome!

Pradeep Relwani
Pradeep Relwani
3 years ago
Reply to  arjun

still not working unlink()

arjun
3 years ago

Not working means?

Si Thu
Si Thu
2 years ago

I am updating information on item table and I want my previously stored image deleted when I update item’s image with new one. I am very new to CI and I don’t exactly know how to use unlink function and where to put it in my edit function?

arjun
2 years ago
Reply to  Si Thu

Hold the previous image path in the variable and after uploading file to server, updating the entry in database delete it.

North
North
2 years ago

Thankyou for best solution it work for me.

DMCA.com Protection Status
7
0
Would love your thoughts, please comment.x
()
x