forked from leftypol/leftypol
31 lines
677 B
PHP
31 lines
677 B
PHP
<?php
|
|
namespace Vichan\Functions\Fs;
|
|
|
|
|
|
function link_or_copy(string $from, string $to) {
|
|
if (!\link($from, $to)) {
|
|
return \copy($from, $to);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function move_or_copy_uploaded(string $from, string $to) {
|
|
if (!\move_uploaded_file($from, $to)) {
|
|
return \copy($from, $to);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
}
|