Reputation: 3968
This is a really bizarre issue that I've been having.
It happens to images that seem to have a name that is similar to something else.
For instance, if I have an image named image0001.png
and I try to display an image with the source of image0010.png
- which doesn't exist - then the image does not display as nothing, or fire onerror image, instead it displays as image0001.png
which does exist.
I have no idea how to to fix this because I don't really know what is going on.
I am using the following code to fetch results from the database and produce a table with item details.
<?php while ($row = $retval->fetch_array()) { ?>
<tr>
<td>
<a href="/path/to/item/<?= $row['id']; ?>.php"><?= $row['id']; ?></a>
</td>
<td>{$row['name']}</td>
<td>
<a href="/path/to/item/<?= $row['id']; ?>.php">
<img src="/images/<?= $row['id']; ?>.jpg" onerror="this.src='/images/error.png';">
</a>
</td>
<td><?= $row['description']; ?></td>
</tr>
<?php } ?>
Upvotes: 1
Views: 69
Reputation: 3968
The obvious other alternative is to use file_exists
, removing the reliance of JavaScript and ensuring that the image is shown if it exists or an error image if not.
<?php while ($row = $retval->fetch_array()) { ?>
<tr>
<td>
<a href='/path/to/item/<?= $row['id']; ?>.php'><?= $row['id']; ?></a>
</td>
<td>{$row['name']}</td>
<td>
<a href='/path/to/item/<?= $row['id']; ?>.php'>
<?php if (file_exists("/images/{$row['id']}.jpg")) { ?>
<img src="/images/<?= $row['id']; ?>.jpg" />
<?php } else { ?>
<img src="/images/error.png" />
<?php } ?>
</a>
</td>
<td><?= $row['description']; ?></td>
</tr>
<?php } ?>
Upvotes: 0
Reputation: 17797
Sounds like mod_speling is enabled on your server.
Requests to documents sometimes cannot be served by the core apache server because the request was misspelled or miscapitalized. This module addresses this problem by trying to find a matching document, even after all other modules gave up.
You can try to disable this apache module in a .htaccess file:
CheckSpelling Off
Upvotes: 1