-
-
Save g1-nhantv/b388ef3b4ff57c69f719c363d7fea399 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// ...[snip]... // | |
function getAllResumeFiles() { | |
$resumeid = WPJOBPORTALrequest::getVar('resumeid'); | |
do_action('wpjobportal_load_wp_pcl_zip'); | |
$data_directory = wpjobportal::$_config->getConfigurationByConfigName('data_directory'); | |
$path = WPJOBPORTAL_PLUGIN_PATH . $data_directory; | |
if ( ! function_exists( 'WP_Filesystem' ) ) { | |
require_once ABSPATH . 'wp-admin/includes/file.php'; | |
} | |
global $wp_filesystem; | |
if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ) { | |
$creds = request_filesystem_credentials( site_url() ); | |
wp_filesystem( $creds ); | |
} | |
if (!$wp_filesystem->exists($path)) { | |
WPJOBPORTALincluder::getJSModel('common')->makeDir($path); | |
} | |
$path .= '/zipdownloads'; | |
if (!$wp_filesystem->exists($path)) { | |
WPJOBPORTALincluder::getJSModel('common')->makeDir($path); | |
} | |
$randomfolder = $this->getRandomFolderName($path); | |
$path .= '/' . $randomfolder; | |
if (!$wp_filesystem->exists($path)) { | |
WPJOBPORTALincluder::getJSModel('common')->makeDir($path); | |
} | |
$archive = new PclZip($path . '/allresumefiles.zip'); | |
$wpdir = wp_upload_dir(); | |
$directory = $wpdir['basedir'] . '/' . $data_directory . '/data/jobseeker/resume_' . $resumeid . '/resume/'; | |
//$scanned_directory = array_diff(scandir($directory), array('..', '.'));// code seems reduntant but showing error on deleted resume file downloads | |
$filelist = ''; | |
$query = "SELECT filename FROM `".wpjobportal::$_db->prefix."wj_portal_resumefiles` WHERE resumeid = ".esc_sql($resumeid); | |
$files = wpjobportal::$_db->get_results($query); | |
foreach ($files AS $file) { | |
$filelist .= $directory . '/' . $file->filename . ','; | |
} | |
$filelist = wpjobportalphplib::wpJP_substr($filelist, 0, wpjobportalphplib::wpJP_strlen($filelist) - 1); | |
$v_list = $archive->create($filelist, PCLZIP_OPT_REMOVE_PATH, $directory); | |
if ($v_list == 0) { | |
die("Error : '" . wp_kses($archive->errorInfo(),WPJOBPORTAL_ALLOWED_TAGS) . "'"); | |
} | |
$file = $path . '/allresumefiles.zip'; | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/octet-stream'); | |
header('Content-Disposition: attachment; filename=' . wpjobportalphplib::wpJP_basename($file)); | |
header('Content-Transfer-Encoding: binary'); | |
header('Expires: 0'); | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
header('Pragma: public'); | |
header('Content-Length: ' . filesize($file)); | |
ob_clean();//this was commented and causing problems | |
flush(); | |
if ( ! function_exists( 'WP_Filesystem' ) ) { | |
require_once ABSPATH . 'wp-admin/includes/file.php'; | |
} | |
global $wp_filesystem; | |
if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ) { | |
$creds = request_filesystem_credentials( site_url() ); | |
wp_filesystem( $creds ); | |
} | |
echo $wp_filesystem->get_contents($file); | |
@wp_delete_file($file); | |
$path = WPJOBPORTAL_PLUGIN_PATH . $data_directory; | |
$path .= '/zipdownloads'; | |
$path .= '/' . $randomfolder; | |
@wp_delete_file($path . '/index.html'); | |
$wp_filesystem->rmdir($path); | |
exit(); | |
} | |
// ...[snip]... // | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment