a few things you're doing wrong at a glance.
1) posting to the wrong forum, this one is for posting finished scripts, not necessarily getting help with problems,
2) using mysql_ functions. They are officially deprecated as of 5.5 and will be removed in a future version. PDO is more secure, faster, and easy to implement.
3) check out fopen() and file_exists(), etc on php.net to see how to properly implement file I/O