use yii\helpers\FileHelper;
public function getUploadedImagePath()
{
$file_tmp_name = $_FILES[ucwords(Yii::$app->controller->id)]['tmp_name']['image'];
$this->hash = hash_file('md5', $file_tmp_name);
$this->extension = 'jpg';
$file_name = hash_file('md5', $file_tmp_name);
return \Yii::getAlias('@attachmentPath') . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . substr($this->hash, 0, 2) . DIRECTORY_SEPARATOR . substr($this->hash, 2, 2) . DIRECTORY_SEPARATOR . $this->hash . '.' . $this->extension;
}
//@attrchmentpath = E:\UPUPW_AP5.5\vhosts\www.hosts.my/uploads\;
//DIRECTORY_SEPARATOR = \
调用方法
if(FileHelper::createDirectory(dirname(this->getUploadedImagePath()))){
print_r(this->getUploadedImagePath());
}
返回格式
E:\UPUPW_AP5.5\vhosts\www.hosts.my/uploads\image\54\4d\544d00040884fdf9e1722785fa231f00.jpg