<?php
	/*
	 *
	 * 2003 - 2020 @ Yal Publicidad - YMS::intalacion
	 * www.yalpublicidad.com
	 * online@yalpublicidad.com
	 *
	 */
	 
	  /* Autorizo acceso */
		//defined( 'MSai' ) or die( '<h2>No dispones de acceso<h2>' );
		
	$msql['error'] = '';
	
	define( "ASPATH", dirname( dirname(__FILE__) ) );
	
	$url	= ( isset( $_POST['url'] ) ) ? urldecode( $_POST['url'] ) : NULL;
	$path	= ASPATH . '/tmp/acsis.zip';
	
	function download_file ($url, $path) {
		if( empty( $url ) ) return false;
		// -- Ubicaion de la instalacion
		$newfilename = $path;
		
		// -- Si existe curl
		if( function_exists( 'curl_init' ) ){
						$newfile = fopen( $newfilename, "wb" );
						 
						$ch = curl_init();
						curl_setopt($ch, CURLOPT_URL, $url);
						curl_setopt($ch, CURLOPT_HEADER, 0);
						curl_setopt($ch, CURLOPT_FILE, $newfile);
						curl_exec ($ch);
						
						curl_close($ch);
						fclose( $newfile );
						
						return 1;
		}
		
		// -- Si no existe curl
		$file = fopen ($url, "rb");
		
		if ($file) {
			$newfile = fopen ($newfilename, "wb");
			
			if ($newfile)
				while(!feof($file)) {
					fwrite($newfile, fread($file, 1024 * 8 ), 1024 * 8 );
				}
				return 1;
		}
		
		if ($file) {
			fclose($file);
		}
		
		if ($newfile) {
			fclose($newfile);
		}
    }
	
	if( $url !=  NULL ){
		echo download_file ($url, $path);
	}
	
	
?>