i am new with php and was trying to upload a file to a specified directory. but when I check the condition given below:
if(file_exists($target_dir))//check if file already exists in uploads folder
{
echo "sorry! file already exists";
$uploadOK=0;
}
it shows that "sorry! file already exists";. but i am picking my imagefile from C:\mypictures\ and path to my target directory is C:\xampp\htdocs\uploads. i am having no idea why is this happening. It would be great if anyone could clarify this.
here is the full code of my upload.php file:
<?php
$target_dir="C:/xampp/htdocs/uploads/";
$target_file=$target_dir.basename($_FILES["fileToUpload"]["name"]);
$uploadOK=1;
$ImageFileType=pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"]))
$check=getimagesize($_FILES["fileToUpload"]["tmp_name"]);//check if a file is an image or not
if($check == true)
echo "file is an image";
else
{
echo "file is not an image";
$uploadOK=0;
}
if(file_exists($target_dir))//check if file already exists in uploads folder
{
echo "sorry! file already exists";
$uploadOK=0;
} //doubt
if(filesize($target_file>500000))//check if the file is too large
{
echo "file too large";
$uploadOK=0;
}
if($ImageFileType!="jpg" && $ImageFileType!="png" && $ImageFileType!="jpeg" && $ImageFileType!="png")//check file type
{
echo "file type not supported";
$uploadOK=0;
}
if($uploadOK==0)//checking for any errors
{
echo "some error occured.";
}
else{
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "file uploaded";
}
else{
echo "file not uploaded....there was some error.";
}
}
?>