fix!: just use upload dir as file upload
This commit is contained in:
parent
d91412d495
commit
b21327a5d3
4
.gitignore
vendored
4
.gitignore
vendored
@ -126,4 +126,6 @@ _modules/*
|
||||
|
||||
/results/
|
||||
/phpunit*.xml
|
||||
/public/.htaccess
|
||||
/public/.htaccess
|
||||
# CocoIndex Code (ccc)
|
||||
/.cocoindex_code/
|
||||
|
||||
@ -50,16 +50,24 @@ class Activities extends Controller {
|
||||
return '';
|
||||
}
|
||||
|
||||
$attachment = trim(str_replace('\\', '/', $attachment));
|
||||
$attachment = ltrim(trim(str_replace('\\', '/', $attachment)), '/');
|
||||
if ($attachment === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (strpos($attachment, 'file/') === 0) {
|
||||
$attachment = substr($attachment, 5);
|
||||
$attachment = 'upload/' . substr($attachment, 5);
|
||||
}
|
||||
|
||||
return ltrim($attachment, '/');
|
||||
if (strpos($attachment, 'upload/legacy/file/') === 0 || strpos($attachment, 'upload/') === 0) {
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
if (preg_match('#^\d{4}/\d{2}/#', $attachment) === 1) {
|
||||
return 'upload/' . $attachment;
|
||||
}
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
|
||||
protected function getAttachmentSubfolder(): string
|
||||
@ -70,7 +78,7 @@ class Activities extends Controller {
|
||||
protected function buildAttachmentRelativePath(string $filename): string
|
||||
{
|
||||
$filename = basename(str_replace('\\', '/', trim($filename)));
|
||||
return $this->getAttachmentSubfolder() . '/' . $filename;
|
||||
return 'upload/' . $this->getAttachmentSubfolder() . '/' . $filename;
|
||||
}
|
||||
|
||||
protected function normalizeAttachmentList(?string $attachments): string
|
||||
@ -1078,7 +1086,7 @@ class Activities extends Controller {
|
||||
}
|
||||
else {
|
||||
$subfolder = $this->getAttachmentSubfolder();
|
||||
$uploadDir = FCPATH . "file/$subfolder/";
|
||||
$uploadDir = FCPATH . "upload/$subfolder/";
|
||||
if (!is_dir($uploadDir)) {
|
||||
mkdir($uploadDir, 0755, true);
|
||||
}
|
||||
|
||||
@ -13,53 +13,11 @@ function resolve_attachment_relative_path($filename) {
|
||||
}
|
||||
|
||||
$normalized = str_replace('\\', '/', ltrim($filename, '/'));
|
||||
$legacyRoot = 'upload/legacy/file';
|
||||
|
||||
$directCandidates = [];
|
||||
if (strpos($normalized, 'file/') === 0 || strpos($normalized, 'upload/') === 0) {
|
||||
$directCandidates[] = $normalized;
|
||||
} else {
|
||||
$directCandidates[] = $legacyRoot . '/' . $normalized;
|
||||
$directCandidates[] = 'upload/' . $normalized;
|
||||
$directCandidates[] = 'file/' . $normalized;
|
||||
if (strpos($normalized, 'upload/') === 0) {
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
foreach ($directCandidates as $candidate) {
|
||||
$absolutePath = FCPATH . str_replace('/', DIRECTORY_SEPARATOR, $candidate);
|
||||
if (is_file($absolutePath)) {
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
$basename = basename($normalized);
|
||||
if ($basename === '') {
|
||||
return $legacyRoot . '/' . $normalized;
|
||||
}
|
||||
|
||||
$flatCandidates = [$legacyRoot . '/' . $basename, 'file/' . $basename, 'upload/' . $basename];
|
||||
foreach ($flatCandidates as $candidate) {
|
||||
$absolutePath = FCPATH . str_replace('/', DIRECTORY_SEPARATOR, $candidate);
|
||||
if (is_file($absolutePath)) {
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
$roots = [$legacyRoot, 'upload', 'file'];
|
||||
foreach ($roots as $root) {
|
||||
$rootPath = FCPATH . $root . DIRECTORY_SEPARATOR;
|
||||
$pattern = $rootPath . '*' . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $basename;
|
||||
$matches = @glob($pattern);
|
||||
if ($matches !== false) {
|
||||
foreach ($matches as $match) {
|
||||
if (is_file($match)) {
|
||||
$relative = str_replace('\\', '/', substr($match, strlen($rootPath)));
|
||||
return $root . '/' . $relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $legacyRoot . '/' . $basename;
|
||||
return 'upload/' . $normalized;
|
||||
}
|
||||
|
||||
$i = 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user