Mapear una unidad de red en Windows con PHP

Aprende a crear y acceder a una unidad de red en Windows desde PHP usando el comando ‘net use’.

function crear_unidad_red($letter){
		$location = "\\\\ip_servidor\\carpeta\\subcarpeta\\etc...";
	    $user = "nombre_de_usuario";
	    $pass = "contraseña";
		if(!is_dir("$letter:")):
			// Map the drive
	    	system("net use ".$letter.": \"".$location."\" ".$pass." /user:".$user." /persistent:no ");
		endif;
		// Borrar unidad
		// system("net use $letter: /delete /y");
	}
	$unidad = 'Z';
	crear_unidad_red($unidad);
	// The location of the PDF file on the server.
	$filename = "$unidad:\\nombre_del_archivo.pdf";
	if(file_exists($filename)):
		// Let the browser know that a PDF file is coming.
		header("Content-type: application/pdf");
		header('Content-Disposition: inline; filename="nombre_del_archivo.pdf"');
		header("Content-Length:".filesize($filename));
		// Send the file to the browser.
		readfile($filename);
	else:
		echo 'No existe el fichero';
	endif;Lenguaje del código: PHP (php)

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Captcha cargando...

Scroll al inicio