Microweber\Utils\Import::queue_import_xls PHP Method

queue_import_xls() public method

public queue_import_xls ( $filename )
    public function queue_import_xls($filename)
    {
        only_admin_access();
        $target_url = 'http://api.microweber.com/service/xls2csv/index.php';
        $file_name_with_full_path = realpath($filename);
        $post = array('test' => '123456', 'file_contents' => '@' . $file_name_with_full_path);
        $result = $this->app->http->url($target_url)->post($post);
        $err = false;
        if ($result != false) {
            $result = json_decode($result, true);
            if (!isset($result['result'])) {
                $err = true;
            }
        } else {
            $err = true;
        }
        if ($err == true) {
            return array('error' => 'Could not contact the Microweber remote server to parse the Excel file. Please try uploading a CSV file.');
        } else {
            if (isset($result['result'])) {
                $url = $result['result'];
                $target_dir = MW_CACHE_DIR . 'backup_restore' . DS . 'excel' . DS;
                if (!is_dir($target_dir)) {
                    mkdir_recursive($target_dir);
                }
                $local_target_file = basename($url);
                $local_target_file = str_ireplace('.xlsx', '.csv', $local_target_file);
                $local_target_file = str_ireplace('.xls', '.csv', $local_target_file);
                $local_save_path = $target_dir . $local_target_file;
                $fp = fopen($local_save_path, 'w+');
                //This is the file where we save the    information
                $ch = curl_init(str_replace(' ', '%20', $url));
                //Here is the file we are downloading, replace spaces with %20
                curl_setopt($ch, CURLOPT_TIMEOUT, 50);
                curl_setopt($ch, CURLOPT_FILE, $fp);
                // write curl response to file
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                curl_exec($ch);
                // get curl response
                curl_close($ch);
                fclose($fp);
                return $this->queue_import_csv($local_save_path);
            }
        }
    }