Destramic Posted January 22, 2007 Share Posted January 22, 2007 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 Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 22, 2007 Share Posted January 22, 2007 constants can't be arrays, correct.update:figured I'd mention you can serialize them in, though, it's a bit messy[code=php:0]define('FILE_UPLOAD_TYPES', serialize(array('image/gif')));if (!in_array('image/gif', unserialize(FILE_UPLOAD_TYPES))){ echo "file not allowed";}[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 Or you could just use a variable ;) Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 22, 2007 Share Posted January 22, 2007 [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 Link to comment Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Share Posted January 22, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 [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. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 22, 2007 Share Posted January 22, 2007 [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! Quote Link to comment Share on other sites More sharing options...
Jenk Posted January 23, 2007 Share Posted January 23, 2007 constants are constant, oddly enough, so your argument of flexibility with a constant is fundamentally flawed.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.