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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:19:46+00:00 2026-06-16T00:19:46+00:00

A Python application is saying the zip files I am streaming via a PHP

  • 0

A Python application is saying the zip files I am streaming via a PHP streamer aren’t zip files. However, winrar opens them with no issues.

This is the headers it is sending:

Content-disposition: filename=example.zip
Content-type: application/zip; charset=binary

Do I need more/different headers?

Below is the code:

<?php
session_start();
if(!$_SESSION['directory']){
    print "Sorry, only logged in users can view downloads";
    exit;
};
?>
<?php

$hidden_file_directory = "download/".$_SESSION['directory']; //Name of the directory where all the sub directories and files exists
$file_path = $_GET['file']; //Get the file from URL variable
$real_file_path = realpath("$hidden_file_directory/$file_path"); //Set the file path w.r.t the download.php... It may be different for u
$filename = basename($real_file_path);

if(dirname($real_file_path) != getcwd() ."/". $hidden_file_directory)
    die("File does not exist.");

if(file_exists($real_file_path)) {
    $content_type = get_mime($real_file_path);
    header("Content-disposition: filename=$filename"); //Tell the filename to the browser
    header("Content-type: $content_type"); //Stream as a binary file! So it would force browser to download
    readfile($real_file_path); //Read and stream the file
}
else {
    echo "File does not exist.";
}


function get_mime($filename) {

    $mime_types = array(

        'txt' => 'text/plain',
        'htm' => 'text/html',
        'html' => 'text/html',
        'php' => 'text/html',
        'css' => 'text/css',
        'js' => 'application/javascript',
        'json' => 'application/json',
        'xml' => 'application/xml',
        'swf' => 'application/x-shockwave-flash',
        'flv' => 'video/x-flv',

        // images
        'png' => 'image/png',
        'jpe' => 'image/jpeg',
        'jpeg' => 'image/jpeg',
        'jpg' => 'image/jpeg',
        'gif' => 'image/gif',
        'bmp' => 'image/bmp',
        'ico' => 'image/vnd.microsoft.icon',
        'tiff' => 'image/tiff',
        'tif' => 'image/tiff',
        'svg' => 'image/svg+xml',
        'svgz' => 'image/svg+xml',

        // archives
        'zip' => 'application/zip',
        'rar' => 'application/x-rar-compressed',
        'exe' => 'application/x-msdownload',
        'msi' => 'application/x-msdownload',
        'cab' => 'application/vnd.ms-cab-compressed',

        // audio/video
        'mp3' => 'audio/mpeg',
        'qt' => 'video/quicktime',
        'mov' => 'video/quicktime',

        // adobe
        'pdf' => 'application/pdf',
        'psd' => 'image/vnd.adobe.photoshop',
        'ai' => 'application/postscript',
        'eps' => 'application/postscript',
        'ps' => 'application/postscript',

        // ms office
        'doc' => 'application/msword',
        'rtf' => 'application/rtf',
        'xls' => 'application/vnd.ms-excel',
        'ppt' => 'application/vnd.ms-powerpoint',

        // open office
        'odt' => 'application/vnd.oasis.opendocument.text',
        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
    );

    $ext = strtolower(array_pop(explode('.',$filename)));
    if (array_key_exists($ext, $mime_types)) {
        return $mime_types[$ext];
    }
    elseif (function_exists('finfo_open')) {
        $finfo = finfo_open(FILEINFO_MIME);
        $mimetype = finfo_file($finfo, $filename);
        finfo_close($finfo);
        return $mimetype;
    }
    else {
        return 'application/octet-stream';
    }
}


?>

Edit – I added:

if(dirname($real_file_path) != getcwd() ."/". $hidden_file_directory)
    die("File does not exist.");

When those who pointed out the insecurity. Hopefully this will be secure enough.

  • 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-16T00:19:47+00:00Added an answer on June 16, 2026 at 12:19 am

    I’ve noticed that some browsers need the filename to be double quoted or they dont know what it is, perhaps python does the same. Try sending

     header("Content-disposition: filename=\"$filename\"");
    

    Also are you sure it is infact application/zip and not application/x-zip-compressed?

    On a side note: You are using the filename directly from the querystring. What if I send my filename as file=..\..\..\..\..\..\systemdir\config.xml? Perhaps you should add some checking. basename() like you use the next step might be a good idea.

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

Sidebar

Related Questions

I have a multithreaded python application that does a bunch of processing on files.
I am developing Python application for Google App Engine on MacOS and I am
In my Python application I have some GtkMenuItems (associated with the main GtkMenuBar), and
I have a Python application in which I would like to monitor the number
I have a Python application in the bottle web-server that accesses a C shared-object
I'm building a Python application that utilizes a bunch of translated strings. The directory
I am writing multi-threaded python application. The main thread create a Thread pool of
I'm trying to run a python application from source, and it has: from shader
I have a small GTK python application that imports a package (Twisted) that may
I'm attempting to package a python application ( Mnemosyne ) using py2app (I didn't

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.