开发者

Symfony and uploadify

I want to use uploadify with Symfony 1.4, but so far I couldn't.

Uploadify loads correctly, I choose my files, it says that the files were successfully uploaded, but the are nowhere.

(I'm doing this on localhost)

Is there开发者_开发问答 anybody who met this problem before?

Thanks, Tom

    $file = $request->getParameter('file');
    $filename = sha1($file->getOriginalName()).$file->getExtension($file->getOriginalExtension());
    $file->save(sfConfig::get('sf_upload_dir').'/'.$filename);


in my project session stored in cookies so I found solution by create extra session storage class

class MySessionStorage extends sfSessionStorage
{
  public function initialize($options = null)
  {
    $request = sfContext::getInstance()->getRequest();

    // work-around for uploadify
    if ($request->getParameter('uploadify') == "onUpload")
    {
      $sessionName = $options["session_name"];
      if($value = $request->getParameter($sessionName))
      {
        session_name($sessionName);
        session_id($value);
      }
    }

    parent::initialize($options);
  }
}

then changed factories.yml to

all:
  storage:
    class: MySessionStorage

and then "uploader" param will like this

uploader      : '<?php echo url_for("attachments/upload?uploadify=onUpload&" . session_name() . "=" . session_id(), true)?>',


I can only guess that it's because you're trying to upload while logged into a system, but flash does not inherit session data from the browser, this means you will always be denied permission to whatever function you are trying to access since symfony thinks you're not logged in.

So you need to manually set variables in order for flash to use the same login session as the browser: jQuery Code (needs to be in a php file, will not work in a js file):

$('#file_upload').uploadify({
  .... config here
  'scriptData': { '<?php echo session_name() ?>': '<?php echo session_id() ?>' }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜