Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

In this Discussion

Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

[ReSolved] Problems in retrieving UserID from Gdn::Session()

edited August 2011 in Vanilla 2.0 - 2.2
I have the uploadify jquery plugin working on my application, and beautifully yesterday.

I put the php script that runs after the file is uploaded into a function in the same controller that renders the button and adds the javascript, and pointed the plugin to it.

I had it working yesterday; it would upload the file, store the file name and user id in the database, then create a thumbnail of the image.

For some reason, however, after an accidental screw up and re-install, the only value returned in this particular script, and entered into the database, is the number 0, which there are no users with an id of 0.

I have tried everything, and have no idea why I can't get the user id anymore.

Any suggestions would be appreciated.

public function Upload($Args) { $Session = Gdn::Session(); // displays the correct user ID echo $Session->UserID; $this->Permission('Gallery.Items.Upload'); $this->AddModule('GalleryHeadModule'); $this->AddModule('GallerySideModule'); $this->AddCssFile('uploadify.css'); $this->AddJsFile('jquery.uploadify.js'); $this->Render(); } /* * Script for the Uploader to run after sucessful upload */ public function UploadProcess() { $Session = Gdn::Session(); $targetFolder = '/uploads'; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('jpg','jpeg','gif','png'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); $Resized = $this->ImageResize($targetFile, $targetFile.'-Thumb.jpg', 100, 100, 0); if ($Resized) { $this->StatusMessage = T("Image Sucessfully Resized"); } else { $this->StatusMessage = T("Image NOT Sucessfully Resized"); } echo '1'; $ItemModel = new ItemModel(); $Count = $ItemModel->GetCount(array('FileName'=> $fileParts['basename'])); // Now the same call produces a zero instead... if ($Count > 0) { $ItemModel->Update('GalleryUpload', array( 'FileName' => $fileParts['basename'], 'InsertUserID' => $Session->UserID, ), array('FileName' => $fileParts['basename'])); } else { $ItemModel->Insert('GalleryUpload', array( 'FileName' => $fileParts['basename'], 'InsertUserID' => $Session->UserID, )); } } else { echo 'Invalid file type.'; } } }


  • SS ✭✭
    edited August 2011
    I tried uploadify (or something similar (flash uploader)) and figured out that the post action from flash doesn't send cookies to server.
    No cookies -> no identify -> Session->UserID is always 0.
  • SS ✭✭
    edited August 2011
    You can try add params to uploadify: UserID and TransientKey.
    In php you can check TransientKey thus:

    $User = Gdn::UserModel()->Get($UserID);
    if ($User && $User->TransientKey == $IncomingTransientKey)
    This is abstract `$User->TransientKey`, TransientKey stored in Attributes (serialized).
    In 2.0.18 there is Session table. I havent seen it in use.
  • zodiacdmzodiacdm
    edited August 2011
    Hmm, some food for thought. I had figured out after the post that the script was being called through flash and thus no session or cookies.

    I am only a rookie at php, and I have been reading up on jquery, ajax and json, though any attempts to pass the data along failed yesterday.

    Thanks for the direction, though, that gives me somewhere to start today.

    It still bothers me that this DID work the other day. I just pulled the UserID from Session(), and it did store in the database. Any idea why?
  • Hmm, alright, so I have the data set up to post in $_Request['UserID'], though it appears that simply calling $_Request in the completion script doesn't work.

    I have tried using Gdn::Request() though I'm not sure how the function works...
  • Alright, got it now, thanks for the help.

    Problem was the post was going to the wrong page since I renamed the file; I was wondering where the redirect was coming from.
Sign In or Register to comment.