dragboatrandy
asked on
PHP File Exists with a wildcard
I have a page that requires a loop to loop through pictures of a specific listing. The previously uploaded and are prefixed with that ID of a particular listing. IE. ListingID = 10284, so the image files are something like this 10284_1.jpg, 10284_2.jpg, etc. What I need to do is use the file exists function in php to find out how many files are in given folder with that prefix (in this case 10284). I have searched but can't find a solution for this particular problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Certainly, as long as $row_rsListings['ListingID '] evaluates to a valid string.
So a bit of confusion for me...
If I have code that in html looks like:
<div class="zip">
<a href="code123.zip"><img src="/images/zip.gif" alt="Download Zip"></a>
</div>
and instead of hard-coding the code123 name I want just grab the zip in the current directory then it would be:
<div class="zip">
<?php
$zip = glob('./*.zip');
echo "<a href=\"$zip\"><img src=\"/images/zip.gi\f" alt=\"Download Zip\"></a>
?>
</div>
If I have code that in html looks like:
<div class="zip">
<a href="code123.zip"><img src="/images/zip.gif" alt="Download Zip"></a>
</div>
and instead of hard-coding the code123 name I want just grab the zip in the current directory then it would be:
<div class="zip">
<?php
$zip = glob('./*.zip');
echo "<a href=\"$zip\"><img src=\"/images/zip.gi\f" alt=\"Download Zip\"></a>
?>
</div>
<div class="zip">
<?php
$zip = glob('./*.zip');
echo "<a href=\"$zip\"><img src=\"/images/zip.gi\f" alt=\"Download Zip\"></a>
?>
</div>
After a few typos and such this is the horrid code that I hacked.
I just want to ensure that there is just one zip file if there is allow the download else error
I just want to ensure that there is just one zip file if there is allow the download else error
<?php
$zipcnt = glob("*.zip");
//echo "Zip = $zip";
echo "Count = ".count($zipcnt)."\n";
if (count($zipcnt) == 1) {
foreach (glob("*.zip") as $zip);
echo "<div class=\"zip\">";
echo "<a href=\"".$zip."\"><img src=\"/images/zip.gif\" alt=\"Download Zip\"></a>";
echo "</div>";
} else {
echo "zip count is wrong ".count($zipcnt);
}
?>
ASKER
<?php $arrImages = glob('../'.$row_rsListings
echo count($arrImages);
?>