-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...
    }

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

In another file when I use print_r( $_SESSION ) it's all right.

animuson
  • 53,861
  • 28
  • 137
  • 147
Pinch Void
  • 13
  • 1

1 Answers1

1

This is a problem I've seen while doing Flex, upload through Flash seems to do not use cookies (and thus loses sessions). If uploadify uses flash this is your problem.

You might fix it by setting a token identifying your user and instead of uploading to http://example.com/upload.php you ought to upload to http://example.com/upload.php?token=azpodkazpoj1dzapdo (you upload script has to implement a mechanism to find and check the user from the token.

EDIT : as suggested in the suspected duplicate question, you can use your session_id as token

AsTeR
  • 7,247
  • 14
  • 60
  • 99