Question:
what is mime type for zip and rar for php upload restrictions?
shadi
2013-04-01 11:12:16 UTC
i tried 'application/x-zip-compressed' and 'application/zip, application/octet-stream' for zip files

also 'application/rar' and 'application/x-rar-compressed, application/octet-stream' for rar files

none worked and all said invalid file type when i uploaded zip and rar files

am i doing something wrong?
Four answers:
2013-04-01 11:30:18 UTC
Here's a function I usually use to upload stuff in php:



/**

* Causes a file to be downloaded to the client.

*

* @param string $source_filename The name of the file to download, as it exists on the server.

* @param string $save_as_filename The name of the file to download, as it is suggested to the user in a Save As-dialog.

*

* @return int The number of bytes downloaded,

* or bool false on failure.

*/

function download_file($source_filename, $save_as_filename)

{

$file = $pathinfo($filename);



switch (strtolower($file['extension'])) {

case 'pdf': $content_type = 'application/pdf'; break;

case 'exe': $content_type = 'application/octet-stream'; break;

case 'zip': $content_type = 'application/zip'; break;

case 'doc': $content_type = 'application/msword'; break;

case 'xls': $content_type = 'application/vnd.ms-excel'; break;

case 'ppt': $content_type = 'application/vnd.ms-powerpoint'; break;

case 'gif': $content_type = 'image/gif'; break;

case 'png': $content_type = 'image/png'; break;

case 'jpg': $content_type = 'image/jpg'; break;

default : $content_type = 'application/force-download'; break;

}



if (ini_get('zlib.output_compression')) {

ini_set('zlib.output_compression', 'Off');

}



header('Pragma: public'); // If this is left out, apparently IE can give problems downloading unusual file types (->page not found)

header('Expires: 0');

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Content-Type: ' . $content_type);

header('Content-Disposition: attachment; filename=' . $save_as_filename);

header('Content-Transfer-Encoding: binary');

header('Content-Length: ' . filesize($source_filename));



return readfile($source_filename);

}
?
2016-12-26 12:50:06 UTC
Mime Type Zip
?
2016-10-18 07:03:20 UTC
Zip Mime Type
student
2016-11-06 08:09:56 UTC
I in uncomplicated terms truly evaluate 2 issues trolling. a million- asserting some thing inflammatory, to not make a factor, yet purely to get a reaction. 2- Pretending to be the different part to lead them to look undesirable. maximum of what is going on right that's 2. permit's settle for it, I say inflammatory issues all the time. yet i'm making a factor.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...