The following code works without errors on my local server but when I put it up on my hosted website, I get a "Failed - Network Error" message immediately.
The way this works is that a button is pressed on a download page to select what file to download. Here's a sample of that code:
<div class="part__head">Get the "<?php echo "{$srcname}";?>"</div>
<div class="part__head">Source file (size: <?php echo "{$srcsize}";?>)</div>
<a href="download/mydloader.php?f=4"><center><img src="images/us_download.png" style="height:35px; width:144px; margin-bottom:.5rem;" alt="download source code"></center> </a>
That code passes the id of the file in the database to mydloader.php. Here's the code of mydloader.php:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
function mydloader($filenumber=NULL){
require '../../php/PDO_Connection_Select.php';
require '../../php/GetUserIpAddr.php';
$ip = GetUserIpAddr();
if (!$pdo = PDOConnect("foxclone_data"))
{
exit("unable to connect to database");
}
$test = $pdo->query("SELECT `filename` FROM files WHERE id = $filenumber");
$filename = $test->fetchColumn();
if (!file_exists($filename)) {
exit("Requested file ($file) does not exist");
}
else {
$file=basename($filename);
$ext = pathinfo($file, PATHINFO_EXTENSION);
$size = filesize($filename);
//Process file for download
ob_clean();
header('Content-Description: File Transfer');
header('Content-Type: ' . mime_content_type($filename));
header('Content-Disposition: attachment; filename='.$filename);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($filename); // Download the file
flush();
exit;
}
}
mydloader($_GET["f"]);
mydloader.php is located in the same folder as the files to be downloaded, so there shouldn't be a path issue. Can somebody please explain why I'm getting an immediate "Failed- Network Error" or point to an issue in my code?