PHP>打开文件而不是强制下载
我想修改一个脚本,我在浏览器中将其购买为'OPEN'文件,而不是'FORCE DOWNLOAD',因为它目前是这样做的。我之前粘贴了代码。PHP>打开文件而不是强制下载
这是它目前的工作原理。
- 用户购买黑莓应用
- 电子邮件与下载链接是 点击。
- 当URL被点击文件'下载'而不是 打开或执行。
我想在用户的手机浏览器中输入URL> OPEN而不是强制下载。当用户收到的链接,它看起来像这样:
http://example.com/delivery/ds-download.php?auth=bKKun8%2BFqpqjo56j1G5SaWNjg3Sgopah2NGf05iXop2k26SRzMlyiXaDiXmWZ2Rwd2aXaaOWamSkpGmqaWqommWUbWaonnVqanVucJWlqKaUnMVznsufk8rPccWll9bGp5Gek9HNlaqklad0zZ6RoaFhxKTPomGXzsSc0HVvzdWV0JWg2NKWmqNuiXm5hWxnnqfGosHUp5%2FDyKWic5rJz5XVl6bIyXJmY2lpbZpnZm5qb5Ccx9SXpMLXmMh1b8nZoMyol6GWZm5mYGhnlmdldGSY2aXL2JdwnZKX066h0NCRx3Q%3D&file=install
谁能帮我更新这个所以它打开而不是下载的力量?
<?php
require_once('ds-config.php');
if (isset($_GET['auth']) === TRUE && isset($_GET['file']) === TRUE) {
if (($product = is_valid_download_request($_GET['auth'])) !== FALSE) {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', FALSE);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($product[3]) . '"');
header('Content-Transfer-Encoding: binary');
if (strcmp(substr($product[3], 0, 7), 'http://') !== 0) {
header('Content-Length: ' . filesize($product[3]));
}
readfile($product[3]);
exit;
}
}
?>
这里是PHP文件的下载链接指向。在遵循下面的重要反馈之后,我现在在文件打开时收到此错误。好消息是,这不是强制下载。感谢那到目前为止!
<?php
/* SETTINGs */
$url_pcmac = "http://www.example.com";
$url_iphone = "http://itunes.apple.com/us/app/";
$url_otherphones = "http://example.com";
$url_bb_42 = $url_otherphones;
$url_bb_43 = $url_otherphones;
$url_bb_45 = "http://example.mobi/F45/i.jad";
$url_bb_46 = "http://example.mobi/F46/i.jad";
$url_bb_47 = "http://example.mobi/F46/i.jad";
$url_bb_50 = "http://example.mobi/F50/i.jad";
$url_bb_60 = "http://example.mobi/F50/i.jad";
/* ************************************* */
/* DO NOT TOUCH ANYTHING UNDER THIS LINE */
/* ************************************* */
/* *UNLESS YOU KNOW WHAT YOU ARE DOING** */
/* ************************************* */
function checkPhone($str) {
$check = stripos($_SERVER['HTTP_USER_AGENT'], $str);
if ($check === false) {
return false;
} else {
return true;
}
}
/* REDIRECT IPHONE AND IPODS */
if(checkPhone("iPhone") || checkPhone("iPod")){
header("Location: ".$url_iphone);
exit();
}
/* REDIRECT BLACKBERRY */
if(checkPhone("BlackBerry")){
$agent = $_SERVER['HTTP_USER_AGENT'];
$osdir = '';
if (eregi("BlackBerry", $agent)) {
if (eregi("6.0", $agent))
header("Location: ".$url_bb_60);
if (eregi("5.0", $agent))
header("Location: ".$url_bb_50);
if (eregi("4.7", $agent))
header("Location: ".$url_bb_47);
if (eregi("4.6", $agent))
header("Location: ".$url_bb_46);
if (eregi("4.5", $agent))
header("Location: ".$url_bb_45);
if (eregi("4.3", $agent))
header("Location: ".$url_bb_43);
if (eregi("4.2", $agent))
header("Location: ".$url_bb_42);
}
exit();
}
/* REDIRECT ALL OTHER PHONES */
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$accept = $_SERVER['HTTP_ACCEPT'];
if(checkPhone("opera mini")
|| checkPhone("android")
|| preg_match('/(pre\/|palm os|palm|hiptop|avantgo|fennec|plucker|xiino|blazer|elaine)/i',$user_agent)
|| preg_match('/(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent)
|| preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)/i',$user_agent)
|| isset($_SERVER['HTTP_X_WAP_PROFILE'])
|| isset($_SERVER['HTTP_PROFILE'])
|| (strpos($accept,'text/vnd.wap.wml')>0)
|| (strpos($accept,'application/vnd.wap.xhtml+xml')>0)){
header("Location: ".$url_otherphones);
exit();
}
/* REDIRECT TO PC and MAC */
header("Location: ".$url_pcmac);
exit();
?>
你只需要设置适当的Content-Type,浏览器应该处理剩余的内容。
例如,您目前使用...
header('Content-Type: application/force-download');
这需要改变,以正确的MIME类型(可能是“应用程序/ vnd.rim.cod”,但是这是一个猜测)。
N.B .:您还需要删除“Content-Disposition”行。
感谢它指向的文件是一个PHP文件。然后,PHP文件检测到BB OS并将它们引导至.jad/cod文件进行安装。 ----你的方向工作,但现在我得到另一个错误,一旦PHP文件打开(注意:这个错误不会发生,当我直接访问它)。 – 90Meatballs 2011-01-13 20:29:39
这是Content-Disposition:附件;那告诉浏览器下载它。
尝试:
header('Content-Disposition: inline; filename="' . basename($product[3]) . '"');
代替。
你不能。浏览器处理下载的方式是用户配置的,无论mime类型是否具有注册的处理程序。但使用诸如`application/force-download`或`application/octet-stream`等MIME类型将始终导致下载。 – 2011-01-13 20:03:16
@ nikc.org。更好的(并且有效的)强制下载的方式是“Content-Disposition:attached”。 – TRiG 2012-07-29 23:46:30