Symfony2 Move uploaded file and SplFileInfo

I took a while to understand that this $fileObject (in Symfony 2 class “File” extends \SplFileInfo) after a move_uploaded_file a call to $fileObject->getMimeType() no longer works.

I really was hoping that the file details would be kept in memory until the code stopped running because I only moved the file.

So mental note is “keep the information on a temp var”.

// …
$files = $request->files->get(‘uploadedfiles’);
// …
$fileObject = $files[0];

if (is_writable($destination)) {
$pathtmp = $fileObject->getRealPath();
$mimetype = $fileObject->getMimeType();
if (!move_uploaded_file($pathtmp, $destination.”algo.csv” )) {
throw new \Exception(“Failed moving file. [” . $pathtmp . “] “);
}
} else {
throw new \Exception(“Destination is not writable. $destination “);
}

Sobre Fernando André
SysAdmin, Website and Application Developer

Deixe uma Resposta

Please log in using one of these methods to post your comment:

Logótipo da WordPress.com

Está a comentar usando a sua conta WordPress.com Terminar Sessão / Alterar )

Imagem do Twitter

Está a comentar usando a sua conta Twitter Terminar Sessão / Alterar )

Facebook photo

Está a comentar usando a sua conta Facebook Terminar Sessão / Alterar )

Google+ photo

Está a comentar usando a sua conta Google+ Terminar Sessão / Alterar )

Connecting to %s

%d bloggers like this: