Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Hide div if image not found

Featured Replies

Hey,

 

I'm new, been designing and building for about 12 years on and off and thought it would be nice to talk to some of you :)

 

I run a photography business. We show the client their images through the web.

I have editors that I send raw images to and they transform them and when ready they upload them.

 

To make it easy for the (non web design) editors to upload the images I give them a HTML doc with relative URL's which link to their 'images' file in the same directory as the HTML doc. All images for each client are named 'T1', 'T2' etc. This means no 'insert image' or any fiddling. They copy and paste the HTML doc beside the images folder and the images are found and used.

 

My problem is that each client has a different amount of images and they have to open the HTML doc in Dreamweaver and delete any unused DIV's manually, we have roughly 60 clients a week so this is a massive pain.

 

BASICALLY - If, image 'T1' not found, hide DIV 'T1'

 

Any help is appreciated, Google returns nothing!

  • Author

Ok, after searching for ages and resulting to making a thread about it, I found the answer 5 minutes later.

 

The answer is php...

 

<?php

$filename = 'images/t1.jpg';

 

if (file_exists($filename)) {

echo "<div id="T1" class="T1">

<img src="images/t1.jpg" alt="Photograph T1" />

</div>";

} else {

echo "";

}

?>

If they want to show all images in the folder then why not just read the folder contents and display what it finds? Then they don't need to edit a document.

Ok, after searching for ages and resulting to making a thread about it, I found the answer 5 minutes later.

 

The answer is php...

 

<?php

$filename = 'images/t1.jpg';

 

if (file_exists($filename)) {

echo "<div id="T1" class="T1">

<img src="images/t1.jpg" alt="Photograph T1" />

</div>";

} else {

echo "";

}

?>

 

 

No need for the else statement. Can leave it with just the if.

  • Author

If they want to show all images in the folder then why not just read the folder contents and display what it finds? Then they don't need to edit a document.

 

It has formatting like putting image titles saying T1 and some info under each picture, so it couldn't just display everything surely?

 

No need for the else statement. Can leave it with just the if.

 

Yeh spotted that when I was adapting it :)

 

Thanks anyway guys, I have a billion other things I'm trying to solve too but I'll search around first

It has formatting like putting image titles saying T1 and some info under each picture, so it couldn't just display everything surely?

 

You can pull meta data from the images, I don't know how plausible that approach would be for you as someone (probably the editors) would have to add the meta data into the image.

 

Meta data can hold alot of useful information, Including things like descriptions, url's, copyrights, authors and so on. And that data will be available wherever the image is transferred (i.e clients computer) and for whoever's using it (search engines, third parties etc.)

 

Just some food for thought.

Edited by bocaj

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.