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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:36:22+00:00 2026-05-27T09:36:22+00:00

if($_POST[‘mode’]==save) { $root = $_SERVER[‘DOCUMENT_ROOT’]; $path = /mcboeking/; $path = $root.$path; $file_path = $_POST[‘path’];

  • 0
if($_POST['mode']=="save") {
$root = $_SERVER['DOCUMENT_ROOT'];
$path = "/mcboeking/";
$path = $root.$path;
$file_path = $_POST['path'];
$file = $path.$file_path;

if(!file_exists($file)) {
    die('file not found');
} else {
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header('Content-Type: application/force-download');
    header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
    header("Content-Length: ".filesize($file));
    readfile($file);}}

As soon as I download the file and open it I get an error message. When i try to open a .doc file I get the message: file structure is invalid.
And when i try to open a .jpg file: This file can not be opened. It may be corrupt or a file format that Preview does not recognize.

But when I download PDF files, they open without any problem.

Can someone help me?

P.s. i tried different headers including :
header(‘Content-Type: application/octet-stream’);

  • 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-05-27T09:36:23+00:00Added an answer on May 27, 2026 at 9:36 am
    $fsize = filesize($yourFilePath); 
    $allowed_ext = array (
    
      // archives
      'zip' => 'application/zip',
    
      // documents
      'pdf' => 'application/pdf',
      'doc' => 'application/msword',
      'xls' => 'application/vnd.ms-excel',
      'ppt' => 'application/vnd.ms-powerpoint',
    
    );
    $mtype = mime_content_type($file_path);
    if ($mtype == '') {
        $mtype = "application/force-download";
    }
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Type: $mtype");
    header("Content-Disposition: attachment; filename=\"$asfname\"");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . $fsize);
    //then ur rest code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$_POST['asdf'] = 'something'; function test() { // NULL -- not what initially expected $string
$arrayOfEmails=$_POST[arrayOfEmails]; 1st question: $arrayOfEmails is now just an array in JSON notation. How would
Author post-edit: Chosen solution (Original question remains below this box) SUMMARY: You SHOULD NOT
#post The names of my variables are not imporant! This code will be deleted
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
First post - hope I'm doing it right! I have a file, lexicon.plist, containing
This post explains how to put file write lock on regular files. But is
I post this here as a last resort. I'm completely stuck and do not
The post I am referring to is this. Not only does the first one
Post-release, I have made one small change to one form in our development site

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.