Now, the files unlinks when I use die() to exit out of script at the end of the function when testing but when I run it normally, nothing gets unlinked and the file remains. The code reaches the unlink() function either way.
Ok. So, when I run the code using the form submit, the file is found and I presume, unlink() runs or begins to or something. However, the file is not deleted. When I run the code again using refresh or by resubmitting the form, the file is not found, but the file is then deleted.
So to summarise:
When the file is found it is not deleted.
When the file is not found it is deleted.
Anyone have any ideas as to what might be happening?
Just a suggestion - have a play with it, formulate your question, then, and only then, ask. You've posted 5 successive posts. Are we to wait for another few? Have you passed on the entire info? Can we start contributing?
I've been sitting in front of it all day testing and nothing makes sense. I'm trying to add anything to the post that I find out so that it might become apparent to someone what the problem may be. I could spend a week trying to figure it out and not ask for any help until the weekend and the solution may have been obvious to someone way beforehand. I'd rather not spend a week on this :)
So in answer to your question. I've passed on as much information as I believe could help resolve the problem and yes, you or anyone else may contribute at any time.
The point is Tinnin, posting a running commentary once your outlined the question isn't necessarily going to help. If a contributor is going to set any time aside to help you, then he or she needs to be aware of the problem in full right in the first post. No added bits or experimental bits or changes - those are bound to infuriate. Let the contributions come. Ok, hope we get some bites then. Busy at the mo, but if nobody takes the hook, I'll be back later. :)
I found a post with a similar problem here Click Here
I added the chmod($emailDir.$attachment, 0777); line before unlink($emailDir.$attachment) and now it is working.
Doesn't make sense to me as no permissions warning was produced without the chmod and unlink() returned true and the file was deleted eventually but with a massive delay. Now it happens instantaneously.