我有链接http://localhost:8081/intranet/slipgaji/2013/1-2013/2013.05.1557.pdf
我将使用代码
if ($file == $profile->profile['nip'] . '.pdf') {
$url_gaji = sprintf($path . "/" . $file);
$search = array('1-', '2-', '3-', '4-', '5', '6', '7', '8', '9', '10', '11', '12');
$replace = array('Jan ', 'Feb ', 'Mar ', 'Apr ', 'Mei ', 'Jun ', 'Jul ', 'Aug ', 'Sept ', 'Oct ', 'Nov ', 'Des ');
$new_dirname = str_replace($search, $replace, $dirname);
$url = sprintf('slipgaji/%s', base64_encode('%sfdjasgkfgdlAJGVLjlvkjlBSBHJ%s'), $file);
echo "<ul id='gaji'><a href='$url' target='_blank' title='gaji'><img src='modules/mod_slipgaji/tmpl/pdf.png' />$new_dirname</a></ul>";
}
但此代码无法通过点击网址显示我的PDF文件请求。在我的地址栏上显示http://localhost:8081/intranet/slipgaji/JXNmZGphc2drZmdkbEFKR1ZMamx2a2psQlNCSEolcw==
请帮帮我...
感谢
答案 0 :(得分:0)
问题是
$url = sprintf('slipgaji/%s', base64_encode('%sfdjasgkfgdlAJGVLjlvkjlBSBHJ%s'), $file);
sprintf的原型是
string sprintf ( string $format [, mixed $args [, mixed $... ]] )
您只需使用格式slipgaji/%s
提供一个输入位置,因此它需要base64_encoded字符串并完全忽略$ file。 JXNmZGphc2drZmdkbEFKR1ZMamx2a2psQlNCSEolcw==
是您在地址栏中看到的base64_encoded字符串。您将要删除base64_encode()
并将其替换为您的文件路径。它最终应该是这样的:
// First %s gets replaced with $new_dirname, second %s is replaced with $file
$url = sprintf('slipgaji/%s/%s', $new_dirname, $file);
在上面的示例中,$ new_dirname应为'2013 / 1-2013',$ file应为'2013.05.1557.pdf'以获取您期望的网址。