Nexous Posted August 13, 2006 Share Posted August 13, 2006 Warning: in_array(): Wrong datatype for second argument in /home/rhuser/public_html/resource/inc/rhu.php on line 67[code]<?php// $file is defined and correct.// $file_ext is defined and correct.// $not_valid_exts is an array.if (!in_array($file_ext, $not_valid_exts) ) {return $file;}?>[/code]I'm not sure how my instance is different from php.net/in_array 's example. Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 13, 2006 Share Posted August 13, 2006 it means that the second parameter, $not_valid_exts, is not actually an array. Quote Link to comment Share on other sites More sharing options...
Nexous Posted August 13, 2006 Author Share Posted August 13, 2006 [code]<?php$not_valid_exts = array('.gif','.png','.jpg','.css','.htm','.html','.htaccess');?>[/code] Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 13, 2006 Share Posted August 13, 2006 are you putting that IMMEDIATELY before the in_array() statement? it's possible that you're defining that in the global scope, and then trying to use it within a function. this is unallowed unless you use $GLOBALS['not_valid_exts'] or you pass it to the function manually. Quote Link to comment Share on other sites More sharing options...
Nexous Posted August 13, 2006 Author Share Posted August 13, 2006 The file defines the array, then calls for '$not_valid_exts'[code]<?php //$file_ext is defined above..$not_valid_exts = array('.gif','.png','.jpg','.css','.htm','.html','.htaccess'); if (!in_array($file_ext, $not_valid_exts) ) {//......}?>[/code] Quote Link to comment Share on other sites More sharing options...
Nexous Posted August 13, 2006 Author Share Posted August 13, 2006 To make it much simplier, I'll explain what I'm trying to do.Don't worry about security features.I want to check valid file extensions..The file is recieved from index.php?file=index.phpSo, I want to check ?file=......[code]<?php$file = $_GET['file'];$valid = array("bad", "worse");if(in_array($file, $valid)){echo 'The File is bad, oh noes!';}else {echo 'We are good, the file is allowed.';}?>[/code]Now to think of it, would I have to split it up? say that the link is ?file=bad/horid.phpWould it still find bad in it, or would I have to split the '/'? Quote Link to comment Share on other sites More sharing options...
Nexous Posted August 14, 2006 Author Share Posted August 14, 2006 *bump* Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 14, 2006 Share Posted August 14, 2006 that looks valid to me, so i don't see what could be causing the parse error. are you still getting the error?for the record, you will not be checking the extension against the array, you will be checking the entire filename. to strip the outermost extension from the filename, use strrchr():[code]$extension = strrchr($filename, '.');[/code]this will INCLUDE the period in the extension. either add periods to each extension you want to check for (as your are currently), or strip the period from the extension you are taking from the filename with substr().as for your original error, try running print_r($not_valid_exts) before running the if() that contains the in_array() function. Quote Link to comment Share on other sites More sharing options...
Nexous Posted August 15, 2006 Author Share Posted August 15, 2006 Thanks, I've got it all sorted out now. 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.