Problem deleting file |
[eluser]macleodjb[/eluser]
I have this function which i am calling from my controller to delete files, but it's not allowing me to unlink the file and i'm not sure why. This is the message i get. Code: Message: unlink() [function.unlink]: http does not allow unlinking Here's my function Code: function delete_file_from_sys($id){ and here's my controller function. Code: function delete_job_file(){
[eluser]TheFuzzy0ne[/eluser]
Quite simply, because the filename you're trying to unlink starts with http://. The base_url() function returns your base_url. You shouldn't use it with unlink(). You just need to specify a relative or absolute path.
[eluser]TheFuzzy0ne[/eluser]
Yes, assuming that files is a directory in the same directory as you're index.php file. Generally it looks nicer to do it like this: Code: unlink('./files/filename.ext'); although with that said, they essentially still do the same thing.
[eluser]macleodjb[/eluser]
ok it works nicely now. I was curious if you knew how i could also integrate a pop up box that allows the user to confirm deletion by saying yes or cancel, something like that.
[eluser]TheFuzzy0ne[/eluser]
Do you know any JavaScript? For anything on my site that requires confirmation, I have a page that actually does the confirming, but also a javascript confirm() dialogue which bypasses the page. Basically, I have a controller method called delete, which accepts two paramters. The first is the ID of the item to be deleted, and the second one accepts the word "confirm". If "confirm" is not passed as the second parameter, then the confirmation page is displayed. If JavaScript is enabled, the confirm dialogue pops up asking the user to confirm the delete, if they don't, the function returns FALSE (so nothing happens), if they do, then the URL for the link is rewritten, and "/confirm" is appended just before it's followed, so they don't get the confirmation page. Basically, if the user doesn't have JavaScript enabled, they still get a confirmation. I hope this makes sense.
[eluser]Vicente Russo[/eluser]
[quote author="TheFuzzy0ne" date="1236464186"]Yes, assuming that files is a directory in the same directory as you're index.php file. Generally it looks nicer to do it like this: Code: unlink('./files/filename.ext'); I`ve made a post on my blog with a few tips on CI. One of them was exactly this "problem". But I didn`t know using ./ is actually the index.php path. So I made a new constant on index.php Code: define('FULLPATH', pathinfo(__FILE__, PATHINFO_DIRNAME)); So if you`r right, and probably true, my constant is unecessary. Just for the record, my post with other tricks: blog post V. |
Welcome Guest, Not a member yet? Register Sign In |