php - error in uploading file to a specified directory -
i new php , trying upload file specified directory. when check condition given below:
if(file_exists($target_dir))//check if file exists in uploads folder { echo "sorry! file exists"; $uploadok=0; }
it shows "sorry! file exists";. picking imagefile c:\mypictures\ , path target directory c:\xampp\htdocs\uploads. having no idea why happening. great if clarify this.
here full code of 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 file image or not if($check == true) echo "file image"; else { echo "file not image"; $uploadok=0; } if(file_exists($target_dir))//check if file exists in uploads folder { echo "sorry! file exists"; $uploadok=0; } //doubt if(filesize($target_file>500000))//check if file large { echo "file 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 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 error."; } } ?>
because checking directory not file. change code to
if(file_exists($target_file))//check if file exists in uploads folder { echo "sorry! file exists"; $uploadok=0; } //do
wiki
Comments
Post a Comment