My program is supposed to create a folder for the uploaded images on the directory but gives this warning:
mkdir() [function.mkdir]: File exists in C:\XAMP\xampp\htdocs\gallery\uploader3.php on line 26
Here is the code:
<html>
<head>
<title> Sample1 - File Upload on Directory </title>
</head>
<body>
<div align="center">
<form action="uploader3.php" method="post" enctype="multipart/form-data" >
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Create an Album (limited to 10 images): <br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<br />
<input type="submit" value="Upload File" />
</form>
</div>
<?php
$target_path = "uploads1/";
if(!mkdir($target_path))
{
die('Failed to create folders...');
}
else
{
for($count = 0; $count < count($_FILES['uploadedfile']); $count++)
{
$target_path = $target_path . basename( $_FILES['uploadedfile']['name'][$count]);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$count], $target_path))
{
echo "The file ". basename( $_FILES['uploadedfile']['name'][$count]).
" has been uploaded";
}
else{
echo "There was an error uploading the file, please try again!";
}
}
}
?>
</body>
</html>
Modify your codes below:
to:
That will check the folder first, if it’s already exist, no need to create it again.
for your 2nd question, you need to store the uploaded image names to somewhere ( i guess DB is a good choice), Then, you can show them anywhere you want.
Or you can use below codes to search in folder and display them: