writeln('Could not create directory: ' . $target . '');
return Command::FAILURE;
}
$output->writeln('Created directory: ' . $target . '');
}
if (file_exists($link) || is_link($link)) {
$output->writeln('The "public/storage" already exists (as a file, directory or link).');
return Command::FAILURE;
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// On Windows, try Junction first as it doesn't require admin privileges
$command = sprintf('mklink /J "%s" "%s"', $link, $target);
exec($command, $cmdOutput, $returnVar);
if ($returnVar === 0) {
$output->writeln('The [public/storage] link has been connected to [storage/uploads] (Junction).');
return Command::SUCCESS;
}
// Fallback to symlink if junction failed (though unlikely)
if (@symlink($target, $link)) {
$output->writeln('The [public/storage] link has been connected to [storage/uploads] (Symlink).');
return Command::SUCCESS;
}
} else {
// On Linux/Unix
if (@symlink($target, $link)) {
$output->writeln('The [public/storage] link has been connected to [storage/uploads].');
return Command::SUCCESS;
}
}
$output->writeln('The links could not be created. Please check permissions.');
return Command::FAILURE;
}
}