I have a script that uses the same filename over and over again for uploads. For example: pic1.jpg, pic2.jpg, picn.jpg where n is an auto_id from the database corresponding to the user.
The script takes a file upload from the user, deletes the old picn.jpg, and then uses move_uploaded_file() to write in the new pic with the same name.
Problem: unlink doesn't work when the whole script runs altogether. In trying to debug, I stopped the script (die()) after unlink()ing and it worked without fail every time. But then I took the die() command back out and it stopped working.
Any ideas??

The script takes a file upload from the user, deletes the old picn.jpg, and then uses move_uploaded_file() to write in the new pic with the same name.
Problem: unlink doesn't work when the whole script runs altogether. In trying to debug, I stopped the script (die()) after unlink()ing and it worked without fail every time. But then I took the die() command back out and it stopped working.
Any ideas??
Code:
if (is_uploaded_file($_FILES['large']['tmp_name'])) {
$pic=$_POST['oldlarge'];
$result=@unlink($pic);
$result=isValid($_FILES,"large"); //isValid() checks for jpegs only
if ($result==0) {
$whereto=$_FILES['large']['name'];
$whereto2=$table.$record_id.".jpg";
move_uploaded_file($_FILES['large']['tmp_name'],$root_dir."/".$o[$piclocation]."/".$whereto2) or print("Couldn't upload files.");
.
.
.
