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 8668997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:21:18+00:00 2026-06-12T18:21:18+00:00

When I upload files to my server from the site it works fine. However,

  • 0

When I upload files to my server from the site it works fine. However, when I try to download them the file is damaged every time. If I open up the file manager on my server I can download the files through this, they work fine. I know the file is uploaded ok, it seems to be an error with the download process.

The files are saved on my server named by their ID in the table, followed by their extension. The name is retrieved from the database and that is used when downloading.

id  |  userid  |  filename   |   extension  |  size
1       2         test.jpeg       jpeg         123456

//the extension column is just for testing, yes I know it's redundant

test.jpeg would be saved on my server as 1.jpeg.

//this is the very first bit of code on the page aside from starting the session
if(isset($_POST['downloadFile'])){
    $file = new fileprocessing;
    $fileID = mysql_real_escape_string($_POST['hiddenFileDownload']);
    $file->serveFile($fileID); 
}

Here is the serveFile function which find the file and allows the user to download it

function serveFile($fileID){
    $sql = mysql_query("select * from files where id = '$fileID'");
    $file = mysql_fetch_array($sql);
    $ext = $file['extension'];

    header('Content-type: image/x-generic'); //I'm trying jpegs only right now

    header('Content-Disposition: attachment; filename="'.$file['filename'].".".$ext.'" ');

    readfile('/home/.../public_html/user_files/'. $fileID.".".$ext.' ');
}

When the file is downloaded it has the correct name. I’m not sure where this is going wrong. Am I not opening the file properly?

edit – adjusted my extension in my servefile function

  • 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-12T18:21:20+00:00Added an answer on June 12, 2026 at 6:21 pm

    As weird as this sounds, I have had issues with viewing “.jpeg” file extensions in the past (i have a site where people have to upload images for products). It is possible however to rename the extension to “.jpg” and view the same file without any interuption. You might try renaming “.jpeg” extensions to “.jpg” when you upload then see if the results of downloading/viewing doesn’t change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to upload a xml file from server side, where the contents of
I am using JSch library to upload file from sdcard to SFTP server but
In my application I want to upload file from SD card to my server.
I'd like to upload a file from a client machine to my server. The
Possible Duplicate: how to upload a audio file from iphone documents folder to server
I am using the BlueImp jQuery-file-upload to upload files to server. The upload accounts
If I upload files to my server and thus have clients/customers download these files.
I want to upload files from a client location to a server. At present,
How can I upload files to server using JSP/Servlet? I tried this: <form action="upload"
I am using CakePHP 2.1 and trying to upload files into server. I can

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.