Download code works on local Apache server - not on web host

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
foxclone
Forum Newbie
Posts: 2
Joined: Thu Feb 24, 2022 7:51 am

Download code works on local Apache server - not on web host

Post by foxclone »

I want to use the following code to allow users to download .iso, .deb, and .tar.gz files from my website on a shared server on my web host, but it fails miserably. Besides the initial warnings, it appears that the readfile command is literally opening and reading the file. It works perfectly on my local Apache server.

Code: Select all

<?php

$php_scripts = '../../php/';
require $php_scripts . 'PDO_Connection_Select.php';
require $php_scripts . 'GetUserIpAddr.php';
function mydloader($l_filename= "")

{
$ip = GetUserIpAddr();
if (!$pdo = PDOConnect("foxclone_data"))
{
exit;
}

{

$file = $l_filename;

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));  /*Read the size of the file*/
    readfile($file);
    exit;
    }
}
/*Clear system output buffer*/
flush();
mydloader($_GET["f"]);
exit;
Here's a link to a screenshot of what happens when run on the webhost since I guess I'm too new to post images:
<a href="https://i.imgur.com/2SqiLu4.png" title="source: imgur.com" /></a>
NOTE: For security, the code will eventually be modified to pass a number to this script and do a lookup in the database to get a filename rather than passing the filename directly.
foxclone
Forum Newbie
Posts: 2
Joined: Thu Feb 24, 2022 7:51 am

Re: Download code works on local Apache server - not on web host

Post by foxclone »

I did, but it didn't help me at all. It's still reading the file instead of sending it. It's not a php.ini problem, they're identical on my local apache server and the web hosts apache server.
theavgdev
Forum Newbie
Posts: 2
Joined: Thu Sep 08, 2022 3:32 pm
Contact:

Re: Download code works on local Apache server - not on web host

Post by theavgdev »

The warnings suggest that you're already outputting something in PDO_Connection_Select.php? What is in your PDO_Connection_Select.php?
Post Reply