ssbhati ssbhati - 2 months ago 5
PHP Question

On upload the image of same name does not display error in php

help me get the error on same name image

<form action="img.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" value=""/>
<input type="submit" value="upload"/>

my action page is.

$image_name = $_FILES["file"]["name"];
$first_char = substr($image_name, 0, 1);

if (!file_exists($first_char)) {

$file = ($_FILES['file']['name']);
$uploadfile = $first_char;
if(file_exists($_FILES['file']['tmp_name'])) {
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile."/".$file);
echo "GOOD";
} else {
echo "ERROR";

as I submit any image it display
on the other hand It work well


You are checking the temporary directory where the image is moved from. But I think you would want to check the destination if theres already a file with the same name.

Try changing if(file_exists($_FILES['file']['tmp_name'])) to if(file_exists($uploadfile."/".$file))