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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.