Jump to content

define variables (array)


Destramic

Recommended Posts

define("FILE_UPLOAD_TYPES", array('image/gif'));

i want to have this variable as a array so i can basically check when people upload if that certain file type is permitted.

[code]
if (!in_array('image/gif', FILE_UPLOAD_TYPES))
{
    echo "file not allowed";
}
[/code]

but it doesnt seem to work...are you not able to sore array's in a define varable?

thanks ricky
Link to comment
Share on other sites

Could probably loop through an array using foreach and set the definition name to the ID... Such as:

foreach($array as $id => $value) {
define($id, $value);
}

But like jesirose and gennericnumber1 hinted at, using defines is incredibly messy and variables are generally better... Honestly the only time I've ever used a define is for error numbers that are used everywhere.
Link to comment
Share on other sites

[quote author=genericnumber1 link=topic=123561.msg510873#msg510873 date=1169503342]
[quote author=jesirose link=topic=123561.msg510869#msg510869 date=1169503292]
Or you could just use a variable ;)
[/quote]

COULD do that, but what if he wanted to add more allowed MIME types later :P
[/quote]

Amazingly enough, one of the cool things about variables is they can vary. They can be changed. It's pretty easy to add another value to an array.
Link to comment
Share on other sites

[quote author=jesirose link=topic=123561.msg510886#msg510886 date=1169503530]
Amazingly enough, one of the cool things about variables is they can vary. They can be changed. It's pretty easy to add another value to an array.
[/quote]

Do I sense a 'lil hostility :P? Fact of the matter is, multiple options are available. Whether it's constants, variables, arrays, etc... serializing constants can be messy though, good luck!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.