I want to upload a text file received via AJAX request in Symfony2 (using Uploadify 2.1.4). How can I process it in an action? I\'ve found some info in the official docs, bu
I found the following simple solution. Maybe it'll be of help to somebody. ;)
The frontend part:
$('#upload-file').uploadify(
{
script: '/upload-file',
folder: '/uploads',
method: 'POST',
uploader: '/bundles/mybundle/flash/uploadify.swf',
cancelImg: '/bundles/mybundle/images/cancel.png',
buttonImg: '/bundles/mybundle/images/upload.png',
width: 48,
height: 48,
auto: false,
queueID: 'fileQueue',
wmode: 'transparent',
fileDataName: 'uploaded_file',
fileDesc: 'Text File (*.txt)',
fileExt: '*.txt',
sizeLimit: 8000000,
multi: true,
simUploadLimit: 3,
onError: function (event, id, fileObj, errorObj)
{
console.log(errorObj.type + ' Error: ' + errorObj.info);
}
});
The backend part:
public function uploadFileAction()
{
$request = $this->getRequest();
$destination = preg_replace('/app$/si', 'web' . $request->request->get('folder'), $this->get('kernel')->getRootDir());
$uploadedFile = $request->files->get('uploaded_file');
$uploadedFile->move($destination, $uploadedFile->getClientOriginalName());
return new Response(1);
}
The issue is closed!