Forum

How to know the file type of the file which you are forcing the user to download?

3 Replies Posted since 25/05/2010

  • matt's profile image

    Member
    matt

    8 Posts

    How to know the file type of the file which you are forcing the user to download?

    I am trying to force the user to download a file. For that my script is:

    $file = "file\this.zip";
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=$file");
    header("Content-Type: application/zip"); //This is what I need
    header("Content-Transfer-Encoding: binary");
    readfile($file);

    The files I am going to upload my not be .zip all the time so I want to know the content type of the image I am going to receive in $file. How to accomplish this

  • matt's profile image

    Member
    matt

    8 Posts

    Replied at 09:40 - 25/05/2010

    Re: How to know the file type of the file which you are forcing the user to download?

    I always put application/octet-stream (or somwething like that) as the browser can't then try and display it in any way, it will always force the user to Save / Run, then the file type is often inferred by the extension.

  • Matt2k's profile image

    Member
    Matt2k

    9 Posts

    Replied at 11:21 - 25/05/2010

    Re: How to know the file type of the file which you are forcing the user to download?

    I am working with a form that allows me to upload files via a local folder and FTP. So I want to move files over ftp (which already works)

    Because of performance reasons I chose this process to run in the background so I use nfcftpput (linux)

    In CLI the following command works perfectly: ncftpput-b-u name -p password -P 1980 127.0.0.1 /upload/ /home/Downloads/upload.zip

    (Knowing that the b-parameter triggers background process) But if I run it via PHP it does not work (without the-b parameter it does)

  • martin's profile image

    Member
    martin

    2 Posts

    Replied at 17:31 - 23/07/2010

    Re: How to know the file type of the file which you are forcing the user to download?

    There's a deprecated function in PHP to obtain the MIME type of a specific file: mime_content_type(string $filename).

  •  

    You must be logged in to post replies

  • Page 1 of 1

Back to top

Sunderland Software City, Evolve Business Centre,
Cygnet Way, Rainton Bridge South Business Park,
Houghton Le Spring, DH4 5QY

Site by SUMO