Hi, I'm asking this question since I'm a bit stuck with GEt php, I know I want to read, not download a txt, either with url externna, I'm new to php, I still struggle a little to understand. I want to create urls like this xxx.php? Link = link method get or so xxx.php? Txt = file.txt What happens that this code only downloads does not read it; "I want you to read me the file that says", I want to know what I'm wrong with :( Thanks my code is
<?php
if (!isset($_GET['file']) || empty($_GET['txt'])) {
exit();
}
$root = "txt/";
$file = basename($_GET['file']);
$path = $root.$file;
$type = '';
if (is_file($path)) {
$size = filesize($path);
if (function_exists('mime_content_type')) {
$type = mime_content_type($path);
}
else if (function_exists('finfo_file')) {
$info = finfo_open(FILEINFO_MIME);
$type = finfo_file($info, $path);
finfo_close($info);
}
if ($type == '') {
$type = "application/force-download";
}
// Definir headers
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=$file");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $size);
// Descargar archivo
readfile($path);
}
else {
die("El archivo txt no existe.");
}
?>