Jump to content

PHP GLOB help?


amwd07

Recommended Posts

I have this simple code below which currently doen't work  ???

all I am trying to do is display Replace Image if files exist in the specific directory

not sure where I'm going wrong?

 

<?php
$dine = $_GET['dine_id'];
foreach (glob("{*.jpg,*.JPG,*.gif,*.GIF}",GLOB_BRACE) as $file) {
if(file_exists("/outlet/id/$dine/".$file)) {
echo "<span><a href=#>Replace Image</a></span>"; }}
?>

Link to comment
https://forums.phpfreaks.com/topic/93429-php-glob-help/
Share on other sites

Sorry I will try to explain clearer

$dine represents the venues id

 

each venue will have it own image library

I want to be able to check if any files exist in the folder if this comes back true

display Replace Image.

 

The replace image page shows all the files in specific directory

ie. outlet/id/185  //// all images show up in this directory but if there are none don't display the replace image link

Link to comment
https://forums.phpfreaks.com/topic/93429-php-glob-help/#findComment-478657
Share on other sites

Yoiur call to glob looks in the current directory, this doesn't look right to me. Maybe something like...

 

<?php

$files = array();
$dine = $_GET['dine_id'];
$files = glob("/outlet/id/$dine/{*.jpg,*.JPG,*.gif,*.GIF}",GLOB_BRACE);
if (count($files)) {
  echo "<span><a href=#>Replace Image</a></span>";
}

?>

 

 

is more like what your after?

Link to comment
https://forums.phpfreaks.com/topic/93429-php-glob-help/#findComment-478666
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.