This commit is contained in:
2021-05-13 18:41:39 +08:00
parent 1ed318c2e0
commit a0aca6c6df
+21 -22
View File
@@ -50,12 +50,16 @@ class File
/** /**
* @return string * @return string
* @throws Exception
*/ */
public function rename(): string public function rename(): string
{ {
if (!empty($this->newName)) { if (!empty($this->newName)) {
return $this->newName; return $this->newName;
} }
if (!file_exists($this->getTmpPath())) {
throw new Exception('(' . $this->name . ')Failed to open stream: No such file or directory');
}
$param = ['tmp_name' => $this->getTmpPath()]; $param = ['tmp_name' => $this->getTmpPath()];
$this->newName = Snowflake::rename($param); $this->newName = Snowflake::rename($param);
return $this->newName; return $this->newName;
@@ -68,33 +72,28 @@ class File
*/ */
public function getContent(): string public function getContent(): string
{ {
// $open = fopen($this->getTmpPath(), 'r'); $open = fopen($this->getTmpPath(), 'r');
@move_uploaded_file($this->tmp_name, storage($this->name)); @move_uploaded_file($this->tmp_name, storage($this->name));
$limit = 1024000;
var_dump(file_get_contents($this->getTmpPath())); $stat = fstat($open);
return ''; $sleep = $offset = 0;
$content = '';
// $limit = 1024000; while ($file = fread($open, $limit)) {
// $content .= $file;
// $stat = fstat($open); fseek($open, $offset);
// if ($sleep > 0) {
// $sleep = $offset = 0; sleep($sleep);
// $content = ''; }
// while ($file = fread($open, $limit)) { if ($offset >= $stat['size']) {
// $content .= $file; break;
// fseek($open, $offset); }
// if ($sleep > 0) { $offset += $limit;
// sleep($sleep); }
// } return $content;
// if ($offset >= $stat['size']) {
// break;
// }
// $offset += $limit;
// }
// return $content;
} }