コード例 #1
0
ファイル: classes.php プロジェクト: nmicht/tlalokes
 /**
  * Executes SQL statement, returns a mysqli_result object or Array if fetched
  *
  * @author Basilio Briceno <*****@*****.**>
  * @param string $sql SQL statement
  * @param boolean $fetch Flag to returns result as a fetched array
  * @param boolean $one_row Flag to return only one fetched row array
  * @return mixed mysqli_result object, fetched array, or FALSE on failure
  */
 public function query($sql, $fetch = false, $one_row = false)
 {
     if (request('debug')) {
         $start_time = microtime(true);
     }
     $result = parent::query($sql);
     if (request('debug')) {
         tf_log('SQL [' . round($start_time - microtime(true), 4) . 's] ' . $sql);
         unset($start_time);
     }
     if ($one_row) {
         $rows = $result->fetch_all(MYSQLI_ASSOC);
         $result->free();
         return $rows[0];
     }
     if ($fetch) {
         $rows = $result->fetch_all(MYSQLI_ASSOC);
         $result->free();
         return $rows;
     }
     return $result;
 }
コード例 #2
0
ファイル: functions.php プロジェクト: nmicht/tlalokes
/**
 * Saves upload files from their temporal path to the configured one
 *
 * @author Basilio Briceno <*****@*****.**>
 * @license http://www.gnu.org/licenses/lgpl.html GNU LGPL
 * @param string $input_name If not set it will try to save everything in _FILES
 * @param array $filter_rule Example: type => pdf, size => 1024
 * @return boolean Returns TRUE if file saved, FALSE if error
 */
function tf_fileup_save($input_name = 'all', $filter_rule = false)
{
    $path = realpath('.') . '/' . conf_get('default', 'uploads');
    // check if _FILES contains an element
    if (count($_FILES) < 1) {
        tf_error('[Upload] No files to save');
        return false;
    } else {
        // save everything in _FILES
        if ($input_name == 'all') {
            foreach ($_FILES as $key => $file) {
                // check file size
                if ($file['size'] > 1) {
                    $save_flag = true;
                    if ($filter_rule) {
                        $save_flag = tf_fileup_filter($key, $filter_rule);
                    }
                    if ($save_flag) {
                        // try to copy file to destination
                        if (!@copy($file['tmp_name'], $path . $file['name'])) {
                            tf_error('[Upload] Cannot write (' . $input_name . ') into ' . $path);
                        }
                        tf_log('Upload: File (' . $file['name'] . ') written into ' . $path);
                    }
                    unset($save_flag);
                }
            }
        }
        // check file existance
        if (!isset($_FILES[$input_name])) {
            tf_error('[Upload] Required input (' . $input_name . ') not found');
            return false;
        } else {
            // check file size
            if ($_FILES[$input_name]['size'] > 1) {
                $save_flag = true;
                if ($filter_rule) {
                    $save_flag = tf_fileup_filter($input_name, $filter_rule);
                }
                if ($save_flag) {
                    // try to copy file to destination
                    if (!@copy($_FILES[$input_name]['tmp_name'], $path . $_FILES[$input_name]['name'])) {
                        tf_error('[Upload] Cannot write (' . $input_name . ') into ' . $path);
                        return false;
                    }
                    tf_log('Upload: File (' . $_FILES[$input_name]['name'] . ') written into ' . $path);
                    return true;
                } else {
                    return false;
                }
                unset($save_flag);
            }
        }
    }
}