php - Generating a string of file names, alternative to global variable? -


i'm creating function users can upload multiple images , upload them server. using global variable matter works, i've heard global variables bad in oop. so, i'm wondering alternative be? (i'm starting php programmer, detailed information appreciated)

code:

function addimgtonieuws($images){      if (isset($images) && $images != "") {         $countfiles = count($images["name"]);          ($i = 0; $i < $countfiles; $i++) {             $filename = $images["name"][$i];             $filetype = $images["type"][$i];             $filesize = $images["size"][$i];             $fileerror = $images["error"][$i];             $filetmp = $images["tmp_name"][$i];              $kaboom = explode(".", $filename);             $fileext = end($kaboom);              $db_file_name = rand(100000, 999999) . "." . $fileext;             $output = $this->db->real_escape_string($db_file_name);              global $string;             $string .= ",$output";             $string = substr($string, 1);         }          echo $string;     }  } 

function addimgtonieuws($images){      if (isset($images) && $images != "") {         throw new exception("bad input bro");     }     $countfiles = count($images["name"]);      $db_names = array();      ($i = 0; $i < $countfiles; $i++) {         $filename = $images["name"][$i];         $filetype = $images["type"][$i];         $filesize = $images["size"][$i];         $fileerror = $images["error"][$i];         $filetmp = $images["tmp_name"][$i];          $kaboom = explode(".", $filename);         $fileext = end($kaboom);          $db_file_name = rand(100000, 999999) . "." . $fileext;         $db_names[] = $this->db->real_escape_string($db_file_name)     }      return $db_names;  } 

assuming wanted $db_names. it's little bit odd escaping here, delay until moment insert in query.

if wanted $db_names string can do:

echo join(",", $obj->addimgtonieuws($images)); 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -