phalcon/cphalcon · error · Phalcon\Assets\Exceptions\TargetPathIsDirectory
Path '{path}' is not a valid target path, it is a directory.
Error message
Path '{path}' is not a valid target path, it is a directory. What it means
Before writing filtered asset output the manager validates the resolved final target path. If is_dir() reports the path as an existing directory it throws TargetPathIsDirectory, because file_put_contents cannot write a file over a directory and the filter step would fail anyway.
Source
Thrown at phalcon/Assets/Manager.zep:471
/**
* Check if the collection have its own target base path
*/
let join = collection->getJoin();
/**
* Check for valid target paths if the collection must be joined
*/
if !join {
/**
* We need a valid final target path
*/
if (true === empty(completeTargetPath)) {
throw new InvalidTargetPath(completeTargetPath);
}
if (true === is_dir(completeTargetPath)) {
throw new TargetPathIsDirectory(completeTargetPath);
}
}
}
/** @var Asset $asset */
for asset in assets {
let filterNeeded = false;
/**
* If the collection must not be joined we must print a HTML for
* each one
*/
if (true !== empty(filters)) {
let sourcePath = asset->getPath();
if (true === asset->isLocal()) {
let filterNeeded = true;
/**
* Get the complete pathView on GitHub (pinned to b7419de9cd)
Solutions
- Point targetPath at a file: `$collection->setTargetPath('css/combined.css')`
- Check `is_dir($targetBasePath . $targetPath)` and pick a name that is not an existing directory
- If the directory name is intentional, rename the directory or choose a distinct output filename
Example fix
// before
$collection->setTargetPath('css'); // 'css' is a directory
// after
$collection->setTargetPath('css/combined.css'); Defensive patterns
Strategy: validation
Validate before calling
$finalTarget = $targetBasePath . $collection->getTargetPath();
if (is_dir($finalTarget)) {
throw new RuntimeException('Asset target path is an existing directory: ' . $finalTarget);
}
echo $assets->outputCss($name); Try / catch
try {
echo $assets->outputCss('header');
} catch (\Phalcon\Assets\Exceptions\TargetPathIsDirectory $e) {
$logger->error('Fix asset target path (points at a directory): ' . $e->getMessage());
throw $e;
} Prevention
- Always set targetPath as a file path including the filename ('css/app.css'), not a folder
- Validate target paths in a build/deploy lint step with is_dir()
- Watch for name collisions between output files and existing directories on case-insensitive filesystems
When it happens
Trigger: A filtered collection whose targetPath resolves to an existing directory, e.g. `setTargetPath('css')` or 'css/' where 'css' is a real folder under targetBasePath, then outputCss()/outputJs().
Common situations: Passing a directory instead of a file path by analogy with other path options; targetPath that collides with a folder name on case-insensitive filesystems; copying a config where the trailing '/app.min.css' segment was dropped.
Related errors
- Path '{path}' is not a valid target path
- Asset '{path}' does not have a valid source path
- Asset '{path}' does not have a valid target path
- Asset '{path}' has the same source and target paths
- Headers have already been sent; cannot emit the response.
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/5308ee85d3a2201a.
Report an issue: GitHub.