I'd say the second is correct, but I'm not a native speaker. A quick Google search reveals thousands of results such as "assign a variable to the file content", but another search returns a lot of results for the other word order ("assign a value to HTML input field").

You want "assign a value to a variable"; it is the variable that is receiving the assignment of something. Think of the same sentence with "price" for "value" and "commodity" for "variable"; you assign a price to a commodity but not the other way around.

Being a math teacher, I immediately began running my classroom dialogue through my head looking for common usage (which of course isn't always correct usage).

So, from the trenches, we say "Assign a value to a variable."

When we take a value, assign it a variable name so we can look at behavior for all possible values, we call that a parameter, rather than a variable.

However, we don't typically assign values to variables. Rather we define variables to represent quantities, and then solve for values of interest under the given conditions.

NOTE: I recognize that the StackExchange is for providing answers, rather than getting into discussions. I offered the above in case @pimvdb was writing in/about an unfamiliar field and could benefit from some "insider" knowledge. If the moderators need to delete this, that won't bother me.

I agree with other answers that "assign a value to a variable" is the most common and generally intended answer. However, there is one occasion where "assign a variable to a value" would make sense: When you are trying to generalize, say, a mathematical example or solution, you can take a value and assign it a variable to generate the solution for all possible values of that variable.

To "assign a value to a variable" is something you tell the computer to do. Once the value has been assigned to the variable, the variable holds that value.

To "assign a variable to a value" is something you do. It means to designate a specific variable to hold a certain value. After you have done this, you intend that the variable will hold that value, but it doesn't actually hold it yet.

So, to "assign a variable to hold the contents of the file" means to create or select a variable that will at some point hold the contents of the file. To "assign the contents of the file to the variable" means to perform the steps so that the variable actually does hold the contents of the file.

When a variable isn't assigned a value, it's actually said to be just declared. A variable declaration and assignment can be (and often is) done in a single statement: var color = "green"; However, the declaration can be done in one statement: var color; and the assignment in another: color = "green"; (Of course, the assignment must follow the declaration and not precede it.) My point is that variable declarations and variable assignments are not the same thing.
–
user39420Mar 13 '13 at 8:12

Well, according to me, assign a value to variable is correct because technically we always assign some value to a variable that holds that assigned value and assign a variable to value is wrong technically. We cannot assign a variable to a value.
Please let me know if there is any confusion.