I use the following code:

$sourcePath = $assetRecord->source->sourceType->getBasePath();
$folderPath = $assetRecord->getFolder()->path;
$path = $sourcePath.$folderPath.$assetRecord->filename;

if (IOHelper::fileExists($path)) {
    $content = IOHelper::getFileContents($assetRecord->url);
    craft()->request->sendFile($test, $content, array('forceDownload' => true));

The fileExists always return false. I use the image all over the site without any problems. Also the $path variable return normal path from inside the public folder.

This code lives inside a custom plugin.

  • What is the question? – Lindsey D Sep 8 '17 at 15:33

IOHelper::fileExists() will return false for a few reasons:

  1. Either PHP's realpath or is_file returns false. i.e. the given path doesn't exist or PHP doesn't have executable permissions on the folders leading up to that path or read permissions on the file itself.

  2. You're using a case-sensitive file system and you're passing in a different cased path/filename than what's on the file system.

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.