HEX
Server: nginx/1.28.1
System: Linux iZgw8b5bpgd4jyptfmmmxgZ 6.6.102-5.2.alnx4.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Nov 27 23:11:10 CST 2025 x86_64
User: www (1000)
PHP: 8.2.28
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.scdc-marine.com/wp-content/plugins/Contact-Form-CFDB7/inc/export-csv.php
<?php
/**
 * CFDB7 csv
 */

if (!defined( 'ABSPATH')) exit;

class Expoert_CSV{

    /**
     * Download csv file
     * @param  String $filename
     * @return file
     */
    public function download_send_headers( $filename ) {
        // disable caching
        $now = gmdate("D, d M Y H:i:s");
        header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
        header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
        header("Last-Modified: {$now} GMT");

        // force download
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");

        // disposition / encoding on response body
        header("Content-Disposition: attachment;filename={$filename}");
        header("Content-Transfer-Encoding: binary");

    }
    /**
     * Convert array to csv format
     * @param  array  &$array
     * @return file csv format
     */
    public function array2csv(array &$array){

        if (count($array) == 0) {
            return null;
        }
        ob_start();

        $df         = fopen("php://output", 'w');
        $array_keys = array_keys($array);
        $heading    = array();
        $unwanted   = array('cfdb7_', 'your-');

        foreach ( $array_keys as $aKeys ) {
            $tmp       = str_replace( $unwanted, '', $aKeys );
            $heading[] = ucfirst( $tmp );
        }
        fputcsv( $df, $heading );

        foreach ( $array['form_id'] as $line => $form_id ) {
            $line_values = array();
            foreach($array_keys as $array_key ) {
                $val = isset( $array[ $array_key ][ $line ] ) ? $array[ $array_key ][ $line ] : '';
                $line_values[ $array_key ] = $val;
            }
            fputcsv($df, $line_values);
        }
        fclose( $df );
        return ob_get_clean();
    }
    /**
     * Download file
     * @return csv file
     */
    public function download_csv_file(){

        global $wpdb;
        $cfdb        = apply_filters( 'cfdb7_database', $wpdb );
        $table_name  = $cfdb->prefix.'db7_forms';

        if( isset($_REQUEST['csv']) && isset( $_REQUEST['nonce'] ) ){

            $nonce =  $_REQUEST['nonce'];
            if ( ! wp_verify_nonce( $nonce, 'dnonce')) {

                wp_die( 'Not Valid.. Download nonce..!! ' );
            }
            $fid     = (int)$_REQUEST['fid'];
            $results = $cfdb->get_results("SELECT form_id, form_value, form_date FROM $table_name
                WHERE form_post_id = '$fid' ORDER BY form_id DESC ",OBJECT);
            $heading_row = $cfdb->get_results("SELECT form_id, form_value, form_date FROM $table_name
                WHERE form_post_id = '$fid' ORDER BY form_id DESC LIMIT 1",OBJECT);
            $heading_row = reset( $heading_row );
            $heading_row = unserialize( $heading_row->form_value );
            $heading_key = array_keys( $heading_row );
           
            $data  = array();
            $i     = 0;
            foreach ($results as $result) :
                
                $i++;
                $data['form_id'][$i]    = $result->form_id;
                $data['form_date'][$i]  = $result->form_date;
                $resultTmp              = unserialize( $result->form_value );
                $upload_dir             = wp_upload_dir();
                $cfdb7_dir_url          = $upload_dir['baseurl'].'/cfdb7_uploads';

                foreach ($resultTmp as $key => $value):
                    if ( ! in_array( $key, $heading_key ) ) continue;
                    if (strpos($key, 'cfdb7_file') !== false ){
                        $data[$key][$i] = $cfdb7_dir_url.'/'.$value;
                        continue;
                    }
                    if ( is_array($value) ){

                        $data[$key][$i] = implode(', ', $value);
                        continue;
                    }

                   $data[$key][$i] = str_replace( array('&quot;','&#039;','&#047;','&#092;')
                    , array('"',"'",'/','\\'), $value );

                endforeach;

            endforeach;

            $this->download_send_headers( "cfdb7-" . date("Y-m-d") . ".csv" );
            echo $this->array2csv( $data );
            die();
        }
    }
}