改名
This commit is contained in:
@@ -44,7 +44,7 @@ class File
|
|||||||
throw new Exception($this->getErrorInfo());
|
throw new Exception($this->getErrorInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@move_uploaded_file($this->tmp_name, $path);
|
file_put_contents($path, $this->_content);
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -60,48 +60,16 @@ class File
|
|||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->newName = md5($this->getContent());
|
$this->_content = file_get_contents($this->getTmpPath());
|
||||||
|
|
||||||
|
$this->newName = md5($this->_content);
|
||||||
|
|
||||||
// $this->newName = Snowflake::rename($this->getTmpPath());
|
// $this->newName = Snowflake::rename($this->getTmpPath());
|
||||||
return $this->newName;
|
return $this->newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function getContent(): string
|
|
||||||
{
|
|
||||||
$open = fopen($this->getTmpPath(), 'r');
|
|
||||||
|
|
||||||
// @move_uploaded_file($this->tmp_name, storage($this->name));
|
|
||||||
|
|
||||||
$limit = 1024000;
|
|
||||||
|
|
||||||
$stat = fstat($open);
|
|
||||||
|
|
||||||
$sleep = $offset = 0;
|
|
||||||
$content = '';
|
|
||||||
while ($file = fread($open, $limit)) {
|
|
||||||
$content .= $file;
|
|
||||||
fseek($open, $offset);
|
|
||||||
if ($sleep > 0) {
|
|
||||||
sleep($sleep);
|
|
||||||
}
|
|
||||||
if ($offset >= $stat['size']) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$offset += $limit;
|
|
||||||
}
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user