1
votes

I want to handle the image uploads with a multi uploader (uploadify or other plugins will do), but I couldn't make it work with symfony.

I tried the swfuploader plugin, but it didn't work, there was an error with javascript.

How can I handle an ajax upload with symfony?

Thanks

3
Can you post peace of code, if you use uploadify, can you post your action(controller) where you get files, and js part. I recommend you use Jquery file upload - denys281

3 Answers

1
votes

It works fine with uploadify on my sites ! But for a more concrete answer you have to supply additional informations on your code.

As a short draft you may take this, please consider about the session_id for symfony security.

jQuery("#myupload").uploadify({
        'script'         : '<?php echo url_for("model/upload")."?".ini_get("session.name") . "=" . session_id(); ?>',
        'scriptData'     : { "sf_user_id": '<?php echo $sf_user_id ?>' }
});


public function executeUpload($request){
    if($request->isMethod("POST")){
        foreach($request->getFiles() as $file){
            /* do what you want with $file */
        }
    }
}

Good luck :-)

0
votes

Symfony 1.4 had some major changes regarding Javascript, the main helper has changes its name so i think that first you should check compatibility between Plugin and Symfony1.4. Also you could add some plugin that enhaces your Javascript programming like Protoculous.

0
votes
public function executeUpload($request){
  if($request->isMethod("POST")){
    foreach($request->getFiles() as $file){
        /* do what you want with $file */
    }
  }
}

How do you read the content of the file?