How to zip a file using symfony

  base64, php, symfony, zip

I uploaded a file and I want to zip it and then encode it in base64. The upload is going well. But when it comes to zipping, I encounter errors.
Here is my controller



namespace AppController;

use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentRoutingAnnotationRoute;
use AppEntityUpload;
use AppFormUploadType;
use DoctrineCommonPersistenceObjectManager;
use DoctrineORMEntityManagerInterface;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationFileExceptionFileException;
use SymfonyComponentHttpFoundationFileUploadedFile;
use SymfonyComponentStringSluggerSluggerInterface;

class FileController extends AbstractController
     * @Route("/home", name="accueil")
    public function index(Request $request, EntityManagerInterface $manager, SluggerInterface $slugger)

        $upload = new Upload();

        $form = $this->createForm(UploadType::class, $upload);


        if($form->isSubmitted() && $form->isValid()) {

            $uploadedFile = $form->get('document')->getData();

            $originalFilename = pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_FILENAME);
            $safeFilename = $slugger->slug($originalFilename);
            $newFilename = $safeFilename.'-'.uniqid().'.'.$uploadedFile->guessExtension();
            try {
            } catch (FileException $e) {
                // ... handle exception if something happens during file upload

            $zip = new ZipArchive();
            if ($zip->open('', ZipArchive::CREATE) == TRUE)
                // Add files to the zip file
                // All files are added, so close the zip file.
            // Get the file and convert into string 
            $zip_f = file_get_contents(''); 
            // Encode the zip file string data into base64 
            $data = base64_encode($zip_f);  
            // Display the output 
            echo $data; 

            return $this->redirectToRoute('accueil');


        return $this->render('file/index.html.twig', array(
            'form' => $form->createView(),

This is the message that i recieve when i run it:

Attempted to load class "ZipArchive" from namespace "AppController".
Did you forget a "use" statement for another namespace?

Source: Symfony Questions