Hi to all, I have scanned most of the forum and found that most of the questions related to my problem is focused on [i]uploading a file and not to overwrite it but to create a new one[/i]. My problem is a little bit different. [b]First[/b], any uploaded file is renamed according to the users name and concatenated by the extension that they are using. Please take note that they can only upload 1 file and it will recieve .jpg,gif,png extensions only.. ex. (demouser.jpg or demouser.gif or demouser.png) [b]Second[/b], when the same user uploaded another file it will first check if a file is existing, if a file exists then it will [b]unlink/delete [/b] the file and upload the new file and if no file exists then it will upload the file. My problem here is the [b]second one[/b].. i have trouble finding if a file is existing. i know im a bit closer but i need your help guys. Many thanks Here is my code: [code] <html> <head> <?php require_once('includes/config.inc'); require_once('includes/constants.php'); require_once('includes/functions.php'); require_once('includes/mysql_connect.php'); session_start(); //Start session $myid = $_SESSION['myid']; $query = "SELECT cli_name FROM tblclients WHERE cli_id = $myid"; $result = @mysql_query($query); $row = mysql_fetch_array($result); $myname = $row[0]; ?> <title>File Uploader </title> </head> <body> <h1>Uploading file...</h1> <?php if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } //Check for correct MIME type if ($_FILES['userfile']['type'] =='image/pjpeg') { $ext = ".jpg"; } elseif ($_FILES['userfile']['type'] =='image/gif') { $ext = ".gif"; } elseif ($_FILES['userfile']['type'] =='image/png') { $ext = ".png"; } else { echo 'Problem: file is not an image'; exit; } //Check if file exists $myfile = '/var/www/html/ecrema/uploads/logos/'.$myname.$ext; $mydir = '/var/www/html/ecrema/uploads/logos/'; if (file_exists($myfile)) { unlink($myfile); //Change the filename to Company's Name + logo $_FILES['userfile']['name'] = $myname.$ext; //Put the file where ur directory is located $upfile = $mydir.$_FILES['userfile']['name']; //echo $upfile.'<br />'; } else { //Change the filename to Company's Name + logo $_FILES['userfile']['name'] = $myname.$ext; //Put the file where ur directory is located $upfile = $mydir.$_FILES['userfile']['name']; //echo $upfile.'<br />'; } if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo 'Problem: could not move file to destination directory'; exit; } } else { echo 'Problem: Possible file upload attack. Filename: '; echo $_FILES['userfile']['name']; exit; } echo 'File uploaded sucessfully<br /><br />'; ?> </body> </html> [/code]