protected function execute(InputInterface $input, OutputInterface $output)
 {
     $directory = dir($input->getArgument('folder'));
     if ($directory) {
         while (false !== ($entry = $directory->read())) {
             if ($entry != '.' && $entry != '..') {
                 $filename = "{$directory->path}{$entry}";
                 //$filename=strtr($filename,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ',
                 //'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
                 $size = filesize($filename);
                 $output->writeln("FILENAME:{$filename}: {$size}");
                 $output->writeln("SIZE:{$size}");
                 //$file=fopen($filename, 'w+',true);
                 $media = new \Application\Sonata\MediaBundle\Entity\Media();
                 $media->setBinaryContent($filename);
                 $output->writeln("MEDIAPATH" . $media->getBinaryContent());
                 $this->getContainer()->get('sonata.media.manager.media')->save($media, 'default', 'sonata.media.provider.podcast');
                 //fclose($file);
                 $output->writeln("save media OK");
             }
         }
         $output->writeln('finish');
     } else {
         $output->writeln("folder doesn't exist");
     }
 }
 protected function saveAlbumImages(&$albumModel, $xml)
 {
     $values = (array) json_decode(json_encode($xml));
     if (!empty($values) && !empty($values["ImageSet"]) && !empty($values["ImageSet"]->LargeImage) && !empty($values["ImageSet"]->LargeImage->URL)) {
         $albumModel->setThumbnailUrl(strval($values["ImageSet"]->LargeImage->URL));
         $filename = explode('/', $albumModel->getThumbnailUrl());
         $filename = $filename[sizeof($filename) - 1];
         $fileDir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/images/albums/';
         if (!file_exists($fileDir)) {
             if (!mkdir($fileDir, 0770, true)) {
                 return;
             }
         }
         $filePath = $fileDir . $filename;
         try {
             $ch = curl_init($albumModel->getThumbnailUrl());
             $fp = fopen($filePath, "w");
             curl_setopt($ch, CURLOPT_FILE, $fp);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_exec($ch);
             curl_close($ch);
             fclose($fp);
             $media = new \Application\Sonata\MediaBundle\Entity\Media();
             $media->setBinaryContent($filePath);
             $media->setContext('default');
             $media->setProviderName('sonata.media.provider.image');
             $albumModel->setImage($media);
         } catch (\Exception $e) {
         }
     }
 }