RMorrison Posted November 19, 2014 Share Posted November 19, 2014 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 https://forums.phpfreaks.com/topic/292577-getting-503-error-on-page-that-loads-every-other-part/ Share on other sites More sharing options...
gizmola Posted November 19, 2014 Share Posted November 19, 2014 Take out all of your suppressions (the @ sign before functions) and run it on your server. What error(s) are you getting? Link to comment https://forums.phpfreaks.com/topic/292577-getting-503-error-on-page-that-loads-every-other-part/#findComment-1497027 Share on other sites More sharing options...
RMorrison Posted November 20, 2014 Author Share Posted November 20, 2014 Worked out the problem. Was actually another part of code causing the issue. Link to comment https://forums.phpfreaks.com/topic/292577-getting-503-error-on-page-that-loads-every-other-part/#findComment-1497113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.