Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * @function select
- * @description Select table rows
- * @param Array $fields
- * @param String $table
- * @param String $arguments (optional)
- * @return Array $rows
- */
- public function select($fields,$table,$arguments=""){
- //var_dump($this->res['connection'],$table);
- $list = ftp_rawlist($this->res['connection'],$table);
- $result = array();
- function not_empty($var){return !empty($var);}
- function perm2octal($s){
- $p = array(
- '-' => 0,
- 'x' => 1,
- 'w' => 2,
- 'r' => 4,
- );
- $r = 0;
- foreach(str_split($s) AS $c){
- $r+=$p[$c];
- }
- return $r;
- }
- foreach($list AS $file){
- if(substr($file,0,1)=='-'){
- $parse = explode(' ',$file);
- $parse = array_filter($parse,"not_empty");
- $t['rights'] = (int) implode(array_map("perm2octal",str_split(substr(array_shift($parse),1),3)));
- $code = array_shift($parse);
- $t['owner'] = array_shift($parse);
- $t['group'] = array_shift($parse);
- $t['size'] = (int) array_shift($parse);
- $last = count($parse)-1;
- $t['name'] = $parse[$last];
- unset($parse[$last]);
- $t['date'] = @strtotime(implode(' ',$parse));
- $return = array();
- if(count($fields)){
- foreach($fields AS $field){
- if(in_array($field,$this->res['fields'])){
- if($field == 'content'){
- $return['content'] = '';
- $tmp = tmpfile();
- ftp_fget($this->res['connection'],$tmp,$table.'/'.$t['name'],FTP_ASCII,0);
- fseek($tmp,0);
- while(!feof($tmp)){
- $return['content'] .= fread($tmp,1024);
- }
- }
- else{
- $return[$field] = $t[$field];
- }
- }
- }
- }
- else{
- $return = $t;
- }
- if(count($return)){ $result[] = $return; }
- }
- }
- $this->res['result'] = $result;
- return $this->_result();
- }
- ?>
Add Comment
Please, Sign In to add comment