I can't get this working.

$filename = Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL) . "media/wysiwyg/Logos/$manufacturerName.png";
$filename = str_replace(" ", "_", $filename);
 if (file_exists($filename)) {

     echo "The file $filename exists";
 } else {
     echo "<img src='$filename' title='$manufacturerName' alt='$manufacturerName' style='float:right;margin:0px' />";

I've tried many ways but it always returns false even thou it the image shows for the not existing echo.

What I'm I doing wrong? Safe mode is off, the files have permissions and the image actually show but in the false echo.


I'm doing it this way now with a new tag I learned about i.e. <object data=. I get a 404 error on using it but no php errors. It works good other than the 404s.

        $_product = $this->getProduct();
        $manufacturerName = $_product->getAttributeText('manufacturer');
        $manufacturerId = $_product->getManufacturer(); 
        $filename = Mage::getBaseDir('media') . "/wysiwyg/Logos/$manufacturerName.png";
        if (empty($filename)) $filename = ''; ?>
    <?php if ($_product->getManufacturer()):?>
        <?php $manufacturerlogo = str_replace(" ", "_", $manufacturerName); ?>
        <?php if (file_exists(Mage::getBaseDir('media') . "/wysiwyg/Logos/$manufacturerlogo.png")): ?>
        <?php $size = getimagesize(Mage::getBaseDir('media') . "/wysiwyg/Logos/$manufacturerlogo.png");
        list($width, $height) = $size;
        $cleanfilename = str_replace(" ", "_", $filename);
        list($width, $height, $type, $attr) = getimagesize($cleanfilename);
    <?php endif ?>
        <object data="<?php echo Mage::getStoreConfig(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL); ?><?php echo 'media/wysiwyg/Logos/'; ?><?php echo $manufacturerlogo; ?><?php echo $this->__('.png"') ?> <?php echo "title='$manufacturerName' alt='$manufacturerName' style='float:right;margin:10px;width:{$width}px;height:{$height}px'"; ?>" type="image/png"></object> 
    <?php endif ?>

I reckon file_exists only work with path and not with URLs that's why your function always displays the image.

Try using Mage::getBaseDir('media') to generate your image path instead.

  • Ill try this out but I might have not stated this to clear. The image exists, but where it's suppose to echo "image exists" it doesn't, even thou the image exist. So I have it echo(ing) where it's NOT suppose to exist :) It shows the image like this but then if the image really doesn't exist it shows a broken image. It's a little confusing the way I have it here. – Freejoy Jan 19 '16 at 20:20
  • Mage::getBaseDir('media') works as far showing when it's suppose to but it breaks the image like this: /home/xxxxx/public_html/media/wysiwyg/Logos/Lladró_Inc.png – Freejoy Jan 19 '16 at 20:55
  • Once you've ensured the image exists using the getBaseDir, you can use your original code to use in the src attribute of the img tag. – Raphael at Digital Pianism Jan 19 '16 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.