<?php
/**
 * Created by PhpStorm.
 * User: myuce
 * Date: 17.11.2016
 * Time: 15:07
 */

namespace AppBundle\Utils;


use Symfony\Component\HttpFoundation\File\UploadedFile;

class FileUploader
{
    private $targetDir;

    public function __construct($targetDir)
    {
        $this->targetDir = $targetDir;
    }

    public function upload(UploadedFile $file)
    {
        $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension();

        $file->move($this->targetDir, $fileName);

        return $fileName;
    }
}