2012-06-10 34 views
-1
function userSingin() 
    { 

      $login = Common::getGLOBALS('userLogin'); 
     $pass = Common::getGLOBALS('userPassword'); 

     $reg = false; 

     $users = $this->db->get("SELECT userID, userLogin, userPassword FROM Users"); 

     foreach($users as $_users) 
     { 
      if($_users->userLogin == $login && $_users->userPassword == md5($pass)) 
      { 
       //$sess->Set('userHash', md5($login.$pass.$salt)); 
       Session::Set('UID', $_users->userID); // set userID 
       $reg = true; 
      } 
     } 

     echo $reg ? "ok" : "error"; 
    } 

================================================= 

    $(function() 
    { 

     $('#file_upload').uploadify(
     { 
      'fileSizeLimit' : '1000KB', 
      'queueSizeLimit' : 1, 
      'fileTypeDesc'  : 'Image Files', 
      'fileTypeExts'  : '*.gif; *.jpg; *.png', 
      'removeTimeout' : 3, 
      'swf'        : '/application/userData/js/uploadify/uploadify.swf', 
      'uploader'   : '/ajax/uploadAvatar/', 

      'onUploadError' : function(file, errorCode, errorMsg, errorString) { 
      alert('The file ' + file.name + ' could not be uploaded: ' + errorString); 
      }, 

      'debug' : true 
       }); 
    }); 

================================================= 

    public function uploadAvatar() 
    { 

     //include_once("application/Tools/Resize.php"); 

     $targetFolder = '/application/userData/upload/avatars/'; 

     if (!empty ($_FILES)) 
     { 
      $tempFile = $_FILES['Filedata']['tmp_name']; 
      $fName = $_FILES['Filedata']['name']; 

      $exp  = explode('.', $fName); 
      $ext  = end($exp); 

      $newName = md5($_FILES['Filedata']['name']. rand(1, PHP_INT_MAX)); 

      $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
      $targetFile = rtrim($targetPath,'/') . '/' . $newName.'.'.$ext; 

      $fileTypes = array('jpg','jpeg','gif','png'); 
      $fileParts = pathinfo($_FILES['Filedata']['name']); 


      if (in_array($fileParts['extension'],$fileTypes)) { 
      move_uploaded_file($tempFile,$targetFile); 
      echo 'file uploaded'; 
      } else { 
      echo 'Invalid file type.'; 
      } 
     } 

     print_r($_SESSION); // empty... 
    } 

=================================================

在另一個文件中,當我使用print_r($_SESSION)時它沒事。

+0

可能重複的[Sessions和uploadify](http://stackoverflow.com/questions/1284666/sessions-and-uploadify) –

回答

1

這是我在做Flex時看到的一個問題,通過Flash上​​傳似乎不使用cookies(因此會失去會話)。如果uploadify使用閃光燈,這是你的問題。

你可以通過設置令牌識別您的用戶修復和代替上傳到http://example.com/upload.php你應該上傳到http://example.com/upload.php?token=azpodkazpoj1dzapdo(您上傳腳本必須實現一種機制,以發現並從令牌檢查該用戶。

編輯:如疑似重複問題中的建議,您可以使用您的session_id作爲標記

+0

是的,我的Uploadify使用Flash。感謝幫助。 –

+0

如果它滿足您的需求,請接受它並歡迎您! – AsTeR

相關問題