leftypol/inc/functions/fs.php

32 lines
677 B
PHP
Raw Normal View History

2025-03-17 23:10:50 +01:00
<?php
namespace Vichan\Functions\Fs;
function link_or_copy(string $from, string $to) {
if (!\link($from, $to)) {
return \copy($from, $to);
}
return true;
}
2025-03-18 11:48:53 +01:00
function move_or_copy_uploaded(string $from, string $to) {
if (!\move_uploaded_file($from, $to)) {
return \copy($from, $to);
}
return true;
}
2025-03-26 00:07:41 +01:00
/**
* Concats two paths accounting for directory separators.
*/
function concat_path(string $base, string $other): string {
if ($base[\strlen($base) - 1] === DIRECTORY_SEPARATOR) {
$base = \substr($base, 0, \strlen($base) - 1);
}
if ($other[0] === DIRECTORY_SEPARATOR) {
return $base . $other;
} else {
return $base . DIRECTORY_SEPARATOR . $other;
}
}