Jump to content

Getting 503 Error on page that loads every other part


RMorrison
Go to solution Solved by RMorrison,

Recommended Posts

I've been trying to do this for a while and can't understand why I'm getting a 503 Error. I'm making a download center which counts the downloads of each file, and the only thing I can't get to work is the actual downloading of the file. It took a while for me to realize I was having an issue as my code works perfectly on my home server.

 

Here is my current code:

function download_file_to_user($target_file, $filename) {    global $user;    $mimetype = (strpos(strtolower($user->browser), 'msie') !== false || strpos(strtolower($user->browser), 'opera') !== false) ? 'application/octetstream' : 'application/octet-stream';    $size = @filesize($target_file);    header('Pragma: public');    header("Content-type: $mimetype");    header("Content-Length: $size");    header('Content-Disposition: attachment; ' . header_filename(htmlspecialchars_decode($filename)));    if (empty($user->browser) || (strpos(strtolower($user->browser), 'msie 6.0') !== false))     {           header('expires: -1');    }    else     {        header('X-Download-Options: noopen');    }    @set_time_limit(0);    $fp = @fopen($target_file, 'rb');    if ($fp !== false)    {        while (!feof($fp))        {            echo fread($fp, 8192);        }        fclose($fp);    }    else    {            @readfile($target_file);    }     flush();}

 
$user is a variable storing all the logged in users data. header_filename is another function but it works perfectly.
 
I know at least part of this code is running because I'm getting the following headers:

Cache-Control max-age=0
Connection close
Content-Disposition attachment; filename=Rayths_CMS_Mod_1_3_1.zip
Content-Length 577244
Content-Type application/octet-stream
Date Wed, 19 Nov 2014 18:46:19 GMT
Expires Wed, 19 Nov 2014 18:46:19 GMT
Pragma public
Server nginx
X-Download-Options noopen
X-Powered-By PHP/5.4.35

 

 

What I don't understand is why this is happening. I used multiple guides and example codes to create this, and I also don't understand why it is working on my home server but not my hosting. Any help would be greatly appreciated.

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.