Hi, i have createed a form to upload .jpg files onto my sever. I am trying to validate whether the file i upload is already existing on my server. I already have a .jpg image on my server but what i am doing is trying to check if the file i upload already exists in my server. For some reason, when i upload any .jpg file it always seems to go into my success message even if the file i upload already exists. Can somebody tel me why? $target = 'Shanghai_2010/images/'; $target .= basename($_FILES['photo']['name']); echo($target); if(!file_exists($target)) { $error = 'This file already exists on the server'; include 'error.html.php'; exit(); } else { // move file to server echo 'success this file does not exist on server'; echo($target); } PHP: I've been doing a bit of debugging to see the value after join the URL to my filename but the value seems fine. However, in my else statement it does not echo my $target variable. Can somebody help
Thanks for the reply, i'm assuimg that the isset is the 'outer' if statement? As i did: if(isset($_FILES['photo'])) { if(!file_exists($target)) { $error = 'This file already exists on the server'; include 'error.html.php'; exit(); } else { // move file to server echo 'success this file does not exist on server'; //echo($target); } } Here is also the form: <form enctype="multipart/form-data" action=" " method="post"> <div> <label for="description"> Description: </label> <input type="text" name="description" id="description" /> <br > </div> <div> <label for="category"> Category </label> <select name="category" id="category"> <option value="Cheng_Huang_Temple">Cheng Huang Temple </option> <option value="Shanghai_Zoo">Shanghai Zoo </option> </select> <br /> </div> <div> <label for="uploadimg"> Upload Photo: </label> <input type="file" id="photo" name="photo" /> <br > </div> <div> <input type="hidden" name="action" value="upload" /> <input type="submit" value="Upload" /> </div> </form> Code (markup): if so, it still goes inton my success message