php validation not working ono $_FILES[]
Posted: Tue Jun 08, 2010 5:32 am
Hi,
i have a html form used to upload .jpg files onto my WAMP server. I am trying to validate if the file uploaded already exists in my server. I already have a .jpg file to test against. What i am having trouble is that whenever i upload any .jpg file no matter if the file exists, it seems to go into my success messsage:
php code snippet:
can somebody tell me why it always goes into my success message?
i have a html form used to upload .jpg files onto my WAMP server. I am trying to validate if the file uploaded already exists in my server. I already have a .jpg file to test against. What i am having trouble is that whenever i upload any .jpg file no matter if the file exists, it seems to go into my success messsage:
Code: Select all
<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: Select all
$target = 'Shanghai_2010/images/';
$target .= basename($_FILES['photo']['name']);
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);
}
}