Kall, you've been going about this all the wrong way. You have cPanel right? Have you gone through it's features lately?
If you have you will see there is a feature called Hotlink Protection. It does exactly what you are trying to accomplish here
Good luck man!