Ciao a tutti , ho un problema con uno script per il download di un file. La variabile $_SESSION['tipo-'.$k] e' stat definita in un altro script e contiene il tipo mime del file. Ottengo i due seguenti errori notice
PHP:
Notice: Undefined variable: k in <b>C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\nologin-online - captcha\download.php on line 19
Notice: Undefined index: tipo- in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\nologin-online - captcha\download.php on line 19
PHP:
<?php
ob_start();
session_start();
function download()
{
$expName = "/^[a-z0-9_.-]+$/i";
if (isset($_POST['newname']) && preg_match($expName, $_POST['newname']))
{
$_SESSION['newname'] = $_POST['newname'];
$_SESSION['extension'] = pathinfo('uploads/',PATHINFO_EXTENSION);
$_SESSION['completename'] = $_SESSION['newname'].'.'.$_SESSION['extension'];
header('Expires: ' . gmdate("D, d M Y H:i:s", 0) . ' GMT');
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header("Content-Type: {$_SESSION['tipo-'.$k]}");
header('Content-Length: ' . (string) filesize($_SESSION['pastepath']));
header("Content-Disposition: attachment; filename=\"{$_SESSION['completename']}\"");
header('Content-Transfer-Encoding: binary');
if (($h = fopen($_SESSION['pastepath'], 'rb')) !== false) {
while (!feof($h) && connection_status() == 0) {
echo fread($h, 1024);
ob_flush();
flush();
}
fclose($h);
}
}
}
session_write_close();
download();
?>