To Joseph things had really gone bad for him. He was rejected and hated by his brothers. They had sold him into slavery. He had been falsely accused and imprisoned. But all of this was used by the Lord for good. Two men from the household of Pharaoh were put in his care in prison. He by the Lord answered them interpreting their dreams. One man restored as the cup barrier and the other hung, as had been prophesied by Joseph.
Then the Lord gave Pharaoh a dream that no one could interpret. Pharaoh's cup bearer having remembered that Joseph could interpret dreams. Joseph is released from prison and interprets Pharaoh's dream from the Lord; seven prosperous years followed by seven years of famine. Pharaoh makes him essentially king of the land, everyone must come to Joseph alone.
Joseph made a plan to store up 1/5 of all the grain from the years of plenty to be used in the coming lean years. Joseph's brothers come to him and he hides who he is. Simeon is kept in prison and the brothers cannot return and unless they bring the youngest Benjamin.
All orchestrated by the Lord to have Israel go to Egypt. This is such a type of Christ it is just incredible. Jesus was rejected and sold at the price of a slave. He was falsely accused and suffered. He was a prophet mighty in word and deed. All authority in heaven and on earth has been given to Him. He sat down at the right and of the Father. He is our intercessor, no one can come to the Father except through Him. Jesus is Lord.
To go to the bible text use this link: http://www.olivetree.com/read/NASB/Genesis/40