Jump to content

Archived

This topic is now archived and is closed to further replies.

AncientSage

Reading extensions, an a bit of arrays...

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.