0

How do I code a function that uses external variables? For example? I have an upload script that I am using repeatedly through a few pages. I'd like to make my code more efficient and just define the upload script as a function and call it every time I need to upload a file.

Is it possible to call a function that has to use external variables like the $_FILES[] variable?

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by ElegantElephant
0

The variables $_FILES, $_GET, $_POST, $_REQUEST, etc. are what's known as super-globals. They are special PHP variables that are available everywhere and are based on the current request PHP so even if the function is in a different file as long as it is the same request they'll be populated with the correct data.

1

So I don't have to define them in the function parameters to be able to use them?

Nope.

function somefunction()
{
   $somefile = $_FILES['hello']; // works perfectly fine.
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.