Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:20:20+00:00 2026-06-05T08:20:20+00:00

I am trying to download uploaded files over https and, while the files themselves

  • 0

I am trying to download uploaded files over https and, while the files themselves download, they cannot be viewed.

I have tried JPG, DOC and XLS files and all give the same problem and, in all cases, if I download via FTP they open perfectly and they open fine in the browser pre-download using the script.

Here is a subset of the script showing the code I am trying to use? Any idea why it downloads garbage?

$_file = sanitiseData($_GET['doc']);
$filename = '/doc_uploads/'.$_file; 
if (file_exists($filename)) { 
header('Content-type:image/jpg');
header('Content-Disposition: attachment; filename="'.$_file.'"');
echo file_get_contents($filename);
} else { 
echo "The file $_file does not exist"; 
} 

Here is a sample of the garbage when trying to view a downloaded JPG via browser:

����JFIF��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90 ��C ��C ��R�”�� ���}!1AQa”q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq”2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?�P��q\�O�^�-�C�z�z����o�N��P;��.i�~k+Զ���|�7`�’e����G�>+���_�6�%�Ԓ��Y�w���P�~.�����2E�� ��”��ڗȌ��ms����[���?��%|”�R5�s�c������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=?V��>���IG�=?V��>���I_Q@w����o���������o����������=GU��>���� �N�v������%|!E~�xO� �ỹx_P����j(�z����_

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:20:21+00:00Added an answer on June 5, 2026 at 8:20 am

    Your best bet is to use readfile(…). PHP’s website has a nice example that should help you. I use it on my website and it works like a charm:

    if (file_exists($file)) {
        // Inform browser that this is a force-download
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        // Inform browser that data can be binary in addition to text
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        // Inform browser that this page expires immediately so that an update to the file will still work.
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        // Push actual file.
        ob_clean();
        flush();
        readfile($file);
        exit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to download a file I have uploaded to an image field
I am trying to download a file over HTTPS and I just keep running
I am trying to download several mp3 files using a script in java. The
I'm trying to make a script for downloading the uploaded files, on the user's
Trying to download file with apache httpclient library and have a problem with resulting
I am creating WCF service that will download & upload xml files. When trying
I am trying to download an entire website using Cyberduck without all video files
Im trying to download share data from a stock exchange using python. The problem
I'm trying to download the source of a particular wikipedia article to my computer.
I'm trying to download a file from an opa database. I've used the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.