Brian W Posted September 15, 2008 Share Posted September 15, 2008 $Restrict = array('.php', '.com', '.exe', '.bat', '.asp', '.dll', '>', '"', '\''); $Filename = eregi_replace($Restrict,"", $_FILES['uploadedfile']['name']); //Removes the restricted extensions and symbols from the file name, this combats sql injection, scripts, and double extensions print_r($Restrict); ?> I can't seem to get eregi_replace to use my array. Can any one tell me why. Thanks. Quote Link to comment Share on other sites More sharing options...
Maq Posted September 15, 2008 Share Posted September 15, 2008 Wild guess but I think because the first parameter of this function takes in a string not an array. So you would have to loop through the array and pass in every string. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 15, 2008 Share Posted September 15, 2008 swap eregi_replace with str_replace no point in using eregi replace if you not using regex. Quote Link to comment Share on other sites More sharing options...
Mchl Posted September 15, 2008 Share Posted September 15, 2008 I think strreplace would work better here... Quote Link to comment Share on other sites More sharing options...
Brian W Posted September 15, 2008 Author Share Posted September 15, 2008 Wild guess but I think because the first parameter of this function takes in a string not an array. So you would have to loop through the array and pass in every string. Possibly, how would I get it to loop through the array? About the str_replace, its case sensitive and I can't seem to use stri_replace with my version of php or something. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 15, 2008 Share Posted September 15, 2008 eregi_replace should still be able to take an array. Quote Link to comment Share on other sites More sharing options...
Mchl Posted September 15, 2008 Share Posted September 15, 2008 so lowercase the other string: $Filename = strtolower($_FILES['uploadedfile']['name']); $Filename = str_replace($Restrict,"", $Filename); eregi_replace() takes strings only Quote Link to comment Share on other sites More sharing options...
Brian W Posted September 15, 2008 Author Share Posted September 15, 2008 Thank you much Mchl. That worked for me... good to know eregi_replace only take strings. Also, thanks every one else for the input. so lowercase the other string: $Filename = strtolower($_FILES['uploadedfile']['name']); $Filename = str_replace($Restrict,"", $Filename); eregi_replace() takes strings only Quote Link to comment Share on other sites More sharing options...
Maq Posted September 15, 2008 Share Posted September 15, 2008 FYI to loop through an array do this: foreach($Restrict as $value) { $Filename = eregi_replace($value,"", $_FILES['uploadedfile']['name']); echo $value; } Quote Link to comment Share on other sites More sharing options...
Brian W Posted September 15, 2008 Author Share Posted September 15, 2008 oh, thats cool... might help in the future as I learn to build more and more complex applications. Thanks Maq 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.