if(file_exists("/img/korica/Design_1.*"))
echo "file exist";
else
echo "there are no files with that name"
-
1this might helpjibsteroos– jibsteroos2019-12-24 08:56:03 +00:00Commented Dec 24, 2019 at 8:56
-
Does this answer your question? PHP: How to check if image file exists?Link182– Link1822019-12-24 08:59:07 +00:00Commented Dec 24, 2019 at 8:59
Add a comment
|
2 Answers
You can use scandir();
$files = scandir("/path/to/directory");
print_r($files);
another example:
<?php
$files = array_filter(scandir('/path/to/directory'), function($item) {
return $item !== '.' && $item !== '..';
});
foreach ($files as $filename)
{
if(file_exists("path/to/directory/$filename"))
{
echo "file exist\n";
}
else
{
echo "file doesn't exist\n";
}
}
Comments
You just need to use :glob() :
$existence= glob("./Yourdir/filename.*");
And then check if $existence has something or not!
It can also be used with a bash-like brace expansion:
glob("./uploads/filename.{jpg,jpeg,png,gif}", GLOB_BRACE).