Question

I'm trying to get a function working to re size any image using a custom module and helper class. For the record I'm running this on a local XAMPP server.

If I pass a image url and a destination url using '/' all works fine. However I need to implement this with DS for future proofing. The following is an example line of code I'm using. with the DS instead of '/'

$newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . "resized" . DS . $fileName;

This returns (without the http or localhost at the start because stackoverflow doesn't allow that even in code) "/test/media/resized\catalog\category\testcat.jpg"

How do I make it so that DS correctly returns forward slashes?

Was it helpful?

Solution

There should be no reason at all to change the DS.

DIRECTORY_SEPARATOR is a predefined PHP constant that is set by your PHP installation itself.

If it is returning the wrong value, it is because your PHP installation is wrong.

Don't adjust Magento to suit a broken PHP install.

OTHER TIPS

This is strictly speaking correct for Windows systems. You probably have to set DS hardcoded, in app/Mage.php change

define('DS', DIRECTORY_SEPARATOR);

to

define('DS', '/');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top