digitalhydra
1/27/2016 - 1:30 AM

download file

download file

if( !empty($_GET['filename']) && !empty($_GET['downloadname']) && file_exists( trailingslashit( wsoe_upload_dir() ).$_GET['filename'].'.csv' ) && wsoe_is_shop_manager() ) {

				$download_filename = $_GET['downloadname'];
				$filename   = trailingslashit( wsoe_upload_dir() ).$_GET['filename'].'.csv';
				$charset = get_option('blog_charset');

				$file = fopen( $filename, 'r' );
				$contents = fread($file, filesize($filename));
				fclose($file);

				header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				header('Content-Description: File Transfer');
				header('Content-Encoding: '. $charset);
				header('Content-type: text/csv; charset='. $charset);
				header("Content-Disposition: attachment; filename=$download_filename.csv");
				header("Expires: 0");
				header("Pragma: public");

				$fh = @fopen( 'php://output', 'w' );
				fwrite( $fh, $contents );
				fclose($fh);
				exit();
			
			}