Here is a pre-written script that does exactly what you want.
Maybe you just want to use the script as-is,
But you can also take a look at the source code and see how they did it 🙂
http://www.digisoft77.com/solutions/e.php?sID=20
ummm ok so how does php know where the file is?
You will find your answer here:
PHP Manual: fopen()
When you use fopen(), you are effectively telling php where the file is:
<?php
$handle = fopen ("/home/rasmus/file.txt", "r");
$handle = fopen ("/home/rasmus/file.gif", "wb");
$handle = fopen ("http://www.example.com/", "r");
?>