Welcome Guest, Not a member yet? Register   Sign In
Does CI not have delete file functionality?
#1

[eluser]zulubanslee[/eluser]
I'm trying to delete an image file from a directory. I tried using 'unlink' but I get an error message that says 'curl does not allow unlinking'. All the research I've done indicates that I have a files permission problem. So what should the file permissions be, and how do I change them to what i need them to be in order to delete it?

Can CI handle this for me or what?

Thanks for your assistance.
#2

[eluser]TWP Marketing[/eluser]
Check the Userguide>file helper:
It's up to you to ensure that the files are writable/owned. Set user permissions for the folder/directory in which those files will be found.
This is from the UserGuide:
Quote:,,,
delete_files('path')

Deletes ALL files contained in the supplied path. Example:
Code:
delete_files('./path/to/directory/');
If the second parameter is set to true, any directories contained within the supplied root path will be deleted as well. Example:
Code:
delete_files('./path/to/directory/', TRUE);
Note: The files must be writable or owned by the system in order to be deleted.
...
#3

[eluser]zulubanslee[/eluser]
Thank for your response. I don't want to delete the entire contents of the directory, I just want to delete one file.
#4

[eluser]TWP Marketing[/eluser]
Then you must change permissions of each and every file which might ever be deleted by your application. I find it easier to change the permissions of the folder and specify that the same permissions be cascaded to all content files.

Whichever way you chose to do this, the point is to set the file permissions to 'writable' by the user/admin etc.
#5

[eluser]zulubanslee[/eluser]
I figured it out. I had the path wrong. I put '/images/'.$image_name, whereas it should have been a relative path: 'images/'.$image_name

Live and learn
#6

[eluser]Aken[/eluser]
Relative paths or absolute paths are what you should use when dealing with files in PHP.

And for reference, to delete a file using PHP you'd use the native unlink() function.
#7

[eluser]TWP Marketing[/eluser]
You're correct, I missed the 'all files' limitation on the file helper.
This might be a useful addition to the file helper utility?




Theme © iAndrew 2016 - Forum software by © MyBB