private function createFile($file) { //echo '<pre>' . print_r('createFile()', true) . '</pre>'; //exit; $extension = $file->guessExtension(); $dir = $this->getUploadDir(); if (!$extension) { $extension = 'bin'; } $newName = $this->createRandCode() . '.' . $extension; $file->move($dir, $newName); /* * Создание и сохранение информации о файле */ $File = new File(); $File->setName($newName); $File->setType($file->getClientMimeType()); $File->setSize($file->getClientSize()); return $File; }
private function createPreviewPicture($entity, $file, $description = '') { if ($file) { $em = $this->getDoctrine()->getManager(); $extension = $file->guessExtension(); $dir = $_SERVER['DOCUMENT_ROOT'] . '/upload/images/'; if (!$extension) { $extension = 'bin'; } $newName = md5(time()) . '.' . $extension; $file->move($dir, $newName); /* * Создание и сохранение информации о файле */ $File = new File(); $File->setName($newName); $File->setType($file->getClientMimeType()); $File->setSize($file->getClientSize()); $File->setDescription($description); $em->persist($File); $entity->setPreviewPicture($File); } }