ouverture même si le fichier a changé de place

This commit is contained in:
Jephté Clain 2024-11-18 20:01:15 +04:00
parent 0bbc07311a
commit 0f71fa0918
2 changed files with 9 additions and 4 deletions

View File

@ -22,7 +22,7 @@ trait TAbstractReader {
$params["ss_type"] = "xlsx"; $params["ss_type"] = "xlsx";
} }
} }
return new $class($reader->tmpName, $params); return new $class($reader->getFile(), $params);
} }
if (is_string($reader)) { if (is_string($reader)) {

View File

@ -4,6 +4,7 @@ namespace nur\sery\file\web;
use nur\sery\cl; use nur\sery\cl;
use nur\sery\file\FileReader; use nur\sery\file\FileReader;
use nur\sery\os\path; use nur\sery\os\path;
use nur\sery\os\sh;
use nur\sery\php\coll\BaseArray; use nur\sery\php\coll\BaseArray;
use nur\sery\ValueException; use nur\sery\ValueException;
@ -103,6 +104,7 @@ class Upload extends BaseArray {
function moveTo(string $dest): bool { function moveTo(string $dest): bool {
if ($this->file === null) { if ($this->file === null) {
sh::mkdirof($dest);
$moved = move_uploaded_file($this->tmpName, $dest); $moved = move_uploaded_file($this->tmpName, $dest);
if ($moved) $this->file = $dest; if ($moved) $this->file = $dest;
} else { } else {
@ -111,8 +113,11 @@ class Upload extends BaseArray {
return $moved; return $moved;
} }
function getFile(): FileReader { function getFile(): string {
$file = $this->file ?? $this->tmpName; return $this->file ?? $this->tmpName;
return new FileReader($file, "r+b"); }
function getReader(): FileReader {
return new FileReader($this->getFile(), "r+b");
} }
} }