This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Uploadify.com plugin for uploading images via ajax

Discussion relating to version 1.2.x stable

Uploadify.com plugin for uploading images via ajax

by dyke.ecl » Tue Apr 14, 2009 9:58 am

Hi everyone, I have problem's with uploading images via ajax/flash script from uploadify.com. Is there any way to set the session_id for symfony, which will be sent by this script? Thanks in advance.
dyke.ecl
Junior Member
 
Posts: 7
Joined: Tue Apr 14, 2009 9:32 am

Re: Uploadify.com plugin for uploading images via ajax

by disturbed » Wed Apr 15, 2009 5:35 pm

To pass session id via url, according to documentation you should turn on php variable session.use_trans_sid.
However, this didn't work for me until i changed session.use_cookies and session.name:
Code: Select all
php_flag session.use_cookies off
php_flag session.use_trans_sid on
php_value session.name symfony

This kind of configuration brings up ton of other problems so i'm still looking for acceptable solution, maybe something like this.
Any ideas?
<img src="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif" border=0 alt="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif"> Dragan
User avatar
disturbed
Member
 
Posts: 36
Joined: Tue Apr 25, 2006 12:04 pm
Location: Zagreb, Croatia

Re: Uploadify.com plugin for uploading images via ajax

by disturbed » Thu Apr 16, 2009 1:02 pm

It seems that Joohns solution works quite well. Class from that examle is not compatible with latest sf 1.2 so here's what i come up with:

Code: Select all
class mySessionStorage extends sfSessionStorage
{
  public function initialize($options = null)
  {

    if($this->transSidFor(sfContext::getInstance()->getRequest()))
    {
      $sessionName = isset($options['session_name']) ? $options['session_name'] : 'symfony' ;

      if($value = sfContext::getInstance()->getRequest()->getParameter($sessionName))
      {
        if (sfConfig::get('sf_logging_enabled'))
   {
     sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Changing session name "%s" to "%s"', $sessionName, $value))));
   }
        session_name($sessionName);
        session_id($value);
      }
    }
   
    parent::initialize($options);
  }
 
  /**
   * Checks if changing of session id is enabled for current module and action.
   * Enabled pairs are set in "app_storage_trans_sid_for" array.
   *  - To enable specific action, add "moduleName/actionName".
   *  - To enable whole module add "moduleName".
   * @return boolean
   */
  private function transSidFor(sfWebRequest $request)
  {
    $for = sfConfig::get("app_storage_trans_sid_for");
    if(!is_array($for) || !$for)
    {
       return false;
    }
    return in_array($request->getParameter("module"), $for) || in_array($request->getParameter("module")."/".$request->getParameter("action"), $for);
  }
}


Turn on new storage class in factories.yml:

Code: Select all
all:
  storage:
    class: mySessionStorage
    param:
      session_name: symfony


Enable session switching for Uploadify actions (in app.yml):
Code: Select all
  storage:
    trans_sid_for: ["myModule/upload", "myModule/fileCheck"]


Creating Uploadify object:
Code: Select all
  $("#fileUpload1").fileUpload({
    'scriptData': {'<? echo ini_get('session.name') ?>':'<? echo session_id() ?>'},
    'uploader': '<? echo public_path("myDir/uploader.swf") ?>',
    'cancelImg': '<? echo public_path("myDir/close.png") ?>',
    'script': '<? echo url_for("@my_route?action=upload") ?>',
    'checkScript': '<? echo url_for("@my_route?action=fileCheck") ?>',
    'folder': '/',
    'multi': true,
    'displayData': 'speed',
    'simUploadLimit': 2
  });
<img src="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif" border=0 alt="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif"> Dragan
User avatar
disturbed
Member
 
Posts: 36
Joined: Tue Apr 25, 2006 12:04 pm
Location: Zagreb, Croatia

Re: Uploadify.com plugin for uploading images via ajax

by superpaul82 » Thu Apr 16, 2009 8:37 pm

Hi! I use this plugin in my local machine, but when I try to upload files I receiver an IO Error..
I use the upload.php file providing by the plugin; is it correct?
Thanks
superpaul82
Member
 
Posts: 43
Joined: Sat Nov 08, 2008 12:45 pm
Location: Tarcento

Re: Uploadify.com plugin for uploading images via ajax

by dyke.ecl » Thu Apr 16, 2009 10:13 pm

disturbed Thank'u so much :) This is great resolution.

However I still got a problem with uploading files. The problem is IO Error #2038( typical problem for uploading files ). It's difficult to debug this kind of problem. I read somewhere that I can tour of mod_rewrite, but it isn't reasonable idea for me. How can I check, what the problem realy is ? :)~ :-)~ :smile:
dyke.ecl
Junior Member
 
Posts: 7
Joined: Tue Apr 14, 2009 9:32 am

Re: Uploadify.com plugin for uploading images via ajax

by disturbed » Fri Apr 17, 2009 11:18 am

superpaul82 wrote: Hi! I use this plugin in my local machine, but when I try to upload files I receiver an IO Error..
I use the upload.php file providing by the plugin; is it correct?
Thanks

I do not use upload.php and check.php - if you gonna use upload.php you are not realy using Symfony in that case.
What you shuld do is a module with actions for upload and file checking (last one is optional), but then you will have to deal with session problem, as explained in previous posts.

dyke.ecl wrote: disturbed Thank'u so much :) ...I still got a problem with uploading files. The problem is IO Error #2038( typical problem for uploading files ). It's difficult to debug this kind of problem. I read somewhere that I can tour of mod_rewrite, but it isn't reasonable idea for me. How can I check, what the problem realy is ? :)~ :-)~ :smile:

Upload works for me with and without mod_rewrite.
Be careful with layout and template in your action - upload request done by Uploadify in some browsers is not registered as XMLHttpRequest (ajax) so layout will be sent by default. You need to force no layout and no template for this action, something like:

Code: Select all
$this->getController()->setRenderMode(sfView::RENDER_NONE);
$this->setLayout(false);

if(/* Upload was successful */)
{
  $this->logMessage("Upload was successful." ;);
  return $this->renderText("1" ;);
}
else
{
  $this->logMessage("Upload was not successful" ;);
  return $this->renderText("0" ;);
}

dyke.ecl wrote: How can I check, what the problem realy is ? :)~ :-)~ :smile:

Check your application logs, see if request is getting to your upload action or there are some errors.
If it gets to action, do some more logging there :D~ :-D~ :grin:
<img src="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif" border=0 alt="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif"> Dragan
User avatar
disturbed
Member
 
Posts: 36
Joined: Tue Apr 25, 2006 12:04 pm
Location: Zagreb, Croatia

Re: Uploadify.com plugin for uploading images via ajax

by roberto » Wed May 27, 2009 2:24 am

disturbed solution worked for me, thank you!!
roberto
Junior Member
 
Posts: 7
Joined: Fri Oct 20, 2006 3:32 am
Location: ViƱa del Mar, Chile.

Re: Uploadify.com plugin for uploading images via ajax

by zooli » Mon Aug 03, 2009 8:59 pm

hi!

thanks for the solution, file upload works, but some other things does not:
i'm using jquery ajax, to add links to a post. i'm storing them in the session object, and when the user saves the form, i'm also saving the links and files data to the database, move the files to their final destination, etc.
the point is, when i upload a file, my session object is gone, or at least i cannot access variables i set with getUser()->setAttribute()

i don't really understand why, i edited the mySessionHandler:
$options['session_id'] = $value;
but that did not solve my case.

any ideas? thanks!
zooli
Junior Member
 
Posts: 1
Joined: Mon Aug 03, 2009 8:52 pm

Re: Uploadify.com plugin for uploading images via ajax

by brainwiz64 » Sun Sep 06, 2009 9:11 pm

Can someone show me how to handle file uploads kn the actions.class.php without using the formValidator? I keep getting HTTP Error with:

Code: Select all
  public function executeUpload(sfWebRequest $request)
  {
    $this->getController()->setRenderMode(sfView::RENDER_NONE);
    $this->setLayout(false);

    $fileName = $this->getRequest()->getFileName('Filedata');
 
    $this->getRequest()->moveFile('Filedata', sfConfig::get('sf_upload_dir').'/'.$fileName);
  return $this->renderText("1" ;);   
}


It looks like getFileName is not a valid method? I'm not sure... please let me know.

Thanks! :)~ :-)~ :smile:
brainwiz64
Junior Member
 
Posts: 4
Joined: Sun May 31, 2009 9:01 pm

Re: Uploadify.com plugin for uploading images via ajax

by disturbed » Tue Sep 08, 2009 12:25 pm

brainwiz64 wrote: It looks like getFileName is not a valid method? I'm not sure... please let me know.

Try using $request->getFiles(...)
<img src="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif" border=0 alt="http://i118.photobucket.com/albums/o83/disturbedHR/userbar/disturbedHR-wb.gif"> Dragan
User avatar
disturbed
Member
 
Posts: 36
Joined: Tue Apr 25, 2006 12:04 pm
Location: Zagreb, Croatia

Re: Uploadify.com plugin for uploading images via ajax

by nfuids » Thu Sep 17, 2009 8:49 pm

Hi!

I tried disturbed solution and I still have no luck.

I'm with sf 1.1..

In order to make sure everything was setup ok, I was using log and it appears that the session_name($sessionName) and session_id($value) are in fact using the correct values.

So when someone uses uploadify to upload a file, the next time he reloads a page or navigate to another page, he's asked to login again.

Any idea?
nfuids
Member
 
Posts: 58
Joined: Fri Apr 20, 2007 4:31 pm
Location: Quebec

Re: Uploadify.com plugin for uploading images via ajax

by mel_06 » Wed Oct 28, 2009 10:20 am

hi guys, i'm just new to symfony. i was wondering how you manage uploadify worked in symfony?

thanks!
mel_06
Member
 
Posts: 33
Joined: Mon Oct 05, 2009 12:52 pm

Re: Uploadify.com plugin for uploading images via ajax

by apulmca2k4 » Sat Mar 05, 2011 11:45 am

Same issue as zooli.

Unable to set attributes using

$this->getUser()->setAttribute();

in the action for uploadify to upload files.

Files are uploading correctly but I am unable to add something in session..

Please suggest.
User avatar
apulmca2k4
Senior Member
 
Posts: 152
Joined: Mon Aug 04, 2008 6:57 am
Location: New Delhi, India

Re: Uploadify.com plugin for uploading images via ajax

by apulmca2k4 » Sat Mar 05, 2011 11:48 am

zooli wrote:hi!

thanks for the solution, file upload works, but some other things does not:
i'm using jquery ajax, to add links to a post. i'm storing them in the session object, and when the user saves the form, i'm also saving the links and files data to the database, move the files to their final destination, etc.
the point is, when i upload a file, my session object is gone, or at least i cannot access variables i set with getUser()->setAttribute()

i don't really understand why, i edited the mySessionHandler:
$options['session_id'] = $value;
but that did not solve my case.

any ideas? thanks!


Having Same issue zooli. Did you find any solution for this?
User avatar
apulmca2k4
Senior Member
 
Posts: 152
Joined: Mon Aug 04, 2008 6:57 am
Location: New Delhi, India

Re: Uploadify.com plugin for uploading images via ajax

by bytestechnolab » Tue Nov 01, 2011 9:14 am

apulmca2k4 wrote:Same issue as zooli.

Unable to set attributes using

$this->getUser()->setAttribute();

in the action for uploadify to upload files.

Files are uploading correctly but I am unable to add something in session..

Please suggest.


Try 'scriptData': { '<?php echo session_name(); ?>': '<?php echo session_id(); ?>' }, as a parameter to uploadify, it will reinitiate same symfony session that you can set or get existing session data.
bytestechnolab
Junior Member
 
Posts: 6
Joined: Mon Oct 31, 2011 3:22 pm

Re: Uploadify.com plugin for uploading images via ajax

by sesss » Tue Jan 03, 2012 2:12 am

nfuids wrote:Hi!

I tried disturbed solution and I still have no luck.

I'm with sf 1.1..

In order to make sure everything was setup ok, I was using log and it appears that the session_name($sessionNamer4) and session_id($value) are in fact using the correct values.

So when someone uses uploadify to upload a file, the next time he reloads a page or navigate to another page, he's asked to login again.

Any idea?

the point is, when i upload a file, my session object is gone, or at least i cannot access variables i set with getUser()->setAttribute()
sesss
Junior Member
 
Posts: 2
Joined: Tue Jan 03, 2012 2:07 am