AncientSage Posted August 2, 2006 Share Posted August 2, 2006 Hello, This code, is supposed to read the name of the uploaded file, and if it doesn't match an extension, then it returns error. However, it just loads, and NOTHING is returned... (not my success script, which is not included here, and does work, or my error script)[code] //Begin query, and this is working, it's a database abstraction layer. $sql = "SELECT config_value FROM config WHERE config_name='allowed_file_ext'"; $extensions = $db->sql_fetchrow($sql); //End Database Query... $read_extensions = '(' . unserialize($extensions) . ')'; if(preg_match("#$read_extensions$#", $_FILES['file']['name'])) { $is_songfile = $_FILES['file']['name']; } else { //error goes here }[/code]The SQL inserted earlier...[code]INSERT INTO phpbb_jukebox_config (config_name, config_value) VALUES ('allowed_file_ext', '{.mid, .mp3, .wav, .aiff}');[/code]Any ideas at to what I am doing wrong here? Link to comment https://forums.phpfreaks.com/topic/16389-reading-extensions-an-a-bit-of-arrays/ Share on other sites More sharing options...
hitman6003 Posted August 2, 2006 Share Posted August 2, 2006 You can't pass an array to preg_match:[code]preg_match("#$read_extensions$#", $_FILES['file']['name'])[/code]Why not use strpos (http://www.php.net/strpos) to do what you want?[code]if (strpos($_FILES['file']['name'], $read_extensions)) {...[/code] Link to comment https://forums.phpfreaks.com/topic/16389-reading-extensions-an-a-bit-of-arrays/#findComment-68195 Share on other sites More sharing options...
AncientSage Posted August 2, 2006 Author Share Posted August 2, 2006 Well, it's returning my error now, but if I upload a file within the allowed extensions, it still returns in error. Probably an SQL error now, that or what it is getting from the database is not what I intend it to, I should be able to fix that.Anyway, thanks for the help. Link to comment https://forums.phpfreaks.com/topic/16389-reading-extensions-an-a-bit-of-arrays/#findComment-68207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.