/** * Saves file in storage * * @param string $sFile * @param string $sDestination * * @return bool|ModuleUploader_EntityItem */ public function Store($sFile, $sDestination = null) { if (!$sDestination) { $oUser = E::ModuleUser()->GetUserCurrent(); if (!$oUser) { return false; } $sDestination = E::ModuleUploader()->GetUserFileDir($oUser->getId()); } if ($sDestination) { $sMimeType = ModuleImg::MimeType($sFile); $bIsImage = strpos($sMimeType, 'image/') === 0; $iUserId = E::UserId(); $sExtension = F::File_GetExtension($sFile, true); if (substr($sDestination, -1) == '/') { $sDestinationDir = $sDestination; } else { $sDestinationDir = dirname($sDestination) . '/'; } $sUuid = ModuleMresource::CreateUuid('file', $sFile, md5_file($sFile), $iUserId); $sDestination = $sDestinationDir . $sUuid . '.' . $sExtension; if ($sStoredFile = E::ModuleUploader()->Move($sFile, $sDestination, true)) { $oStoredItem = E::GetEntity('Uploader_Item', array('storage' => 'file', 'uuid' => $sUuid, 'original_filename' => basename($sFile), 'url' => $this->Dir2Url($sStoredFile), 'file' => $sStoredFile, 'user_id' => $iUserId, 'mime_type' => $sMimeType, 'is_image' => $bIsImage)); return $oStoredItem; } } return false; }
/** * Returns uniq ID of mresource * * @return string */ public function GetUuid() { $sResult = $this->getProp('uuid'); if (!$sResult) { if ($this->GetStorage() == 'file') { $sResult = ModuleMresource::CreateUuid($this->GetStorage(), $this->GetPathFile(), $this->GetHashFile(), $this->GetUserId()); } elseif (!$this->GetStorage()) { $sResult = $this->GetHashUrl(); } $this->setProp('uuid', $sResult); } return $sResult; }