Jump to content


Photo

Reading extensions, an a bit of arrays...


  • Please log in to reply
2 replies to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 02 August 2006 - 11:16 PM

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)

        //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
 }

The SQL inserted earlier...

INSERT INTO phpbb_jukebox_config (config_name, config_value) VALUES ('allowed_file_ext', '{.mid, .mp3, .wav, .aiff}');

Any ideas at to what I am doing wrong here?

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 02 August 2006 - 11:33 PM

You can't pass an array to preg_match:

preg_match("#$read_extensions$#", $_FILES['file']['name'])

Why not use strpos (http://www.php.net/strpos) to do what you want?

if (strpos($_FILES['file']['name'], $read_extensions)) {...


#3 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 02 August 2006 - 11:53 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users