/** * @param MediaInterface|null $interface * @param File $file * @param string $thumb * @return bool */ protected function createNewImageRecord(MediaInterface $interface = null, File $file, $thumb = '') { if (null === $interface) { return false; } if (false == ($row = $interface->find(['hash' => $file->getHash()]))) { return $interface->insert([$interface->getFieldOriginalName() => $file->getOriginalName(), $interface->getFieldSaveName() => $file->getFilename(), $interface->getFieldSavePath() => str_replace(DIRECTORY_SEPARATOR, '/', $file->getRelativePath()), $interface->getFieldThumbnilPath() => $thumb, $interface->getFieldHash() => $file->getHash(), $interface->getFieldSize() => $file->getSize(), $interface->getFieldExt() => $file->getExtension()]); } return $row['id']; }
/** * @return $this */ public function upload() { foreach ($this->files as $file) { $moveFile = $this->config['path'] . DIRECTORY_SEPARATOR . $file->getHash() . '.' . $file->getOriginalExtension(); if (!file_exists($moveFile)) { if (!move_uploaded_file($file->getTmpName(), $moveFile)) { continue; } } $uploaded = new File($moveFile); $uploaded->setHash($file->getHash()); $uploaded->setOriginalName($file->getName()); $uploaded->setOriginalExtension($file->getOriginalExtension()); $uploaded->setRelativePath(str_replace(realpath('./') . DIRECTORY_SEPARATOR, '', realpath($moveFile))); $this->uploadedInfo[] = $uploaded; } unset($uploaded); return $this; }