Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
[ReSolved] Problems in retrieving UserID from Gdn::Session()
zodiacdm
✭
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.
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.';
}
}
}
Tagged:
0
Best Answer
-
S ✭✭You can try add params to uploadify: UserID and TransientKey.
In php you can check TransientKey thus:
Update:
$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.
0
Answers
No cookies -> no identify -> Session->UserID is always 0.
In php you can check TransientKey thus: Update:
This is abstract `$User->TransientKey`, TransientKey stored in Attributes (serialized).
In 2.0.18 there is Session table. I havent seen it in use.
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.
Edit:
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?
I have tried using Gdn::Request() though I'm not sure how the function works...
Problem was the post was going to the wrong page since I renamed the file; I was wondering where the redirect was coming from.