dongle2627 2013-12-26 03:39
浏览 95

php失败url编码器

I have link http://localhost:8081/intranet/slipgaji/2013/1-2013/2013.05.1557.pdf I will mask URL in address bar with put the code

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>";
}

but this code can't showing my PDF file request by click URL. on my address bar shown http://localhost:8081/intranet/slipgaji/JXNmZGphc2drZmdkbEFKR1ZMamx2a2psQlNCSEolcw== please help me for this...

thanks

  • 写回答

1条回答 默认 最新

  • duanmao1975 2013-12-26 04:01
    关注

    The problem is

    $url = sprintf('slipgaji/%s', base64_encode('%sfdjasgkfgdlAJGVLjlvkjlBSBHJ%s'), $file);
    

    The prototype for sprintf is

    string sprintf ( string $format [, mixed $args [, mixed $... ]] )
    

    You only provide one place to input to with your format slipgaji/%s, so it takes the base64_encoded string and ignores $file completely. JXNmZGphc2drZmdkbEFKR1ZMamx2a2psQlNCSEolcw== is the base64_encoded string you see in your address bar. You'll want to get rid of that base64_encode() and replace it with your path to the file. It should end up something like this:

    // First %s gets replaced with $new_dirname, second %s is replaced with $file
    $url = sprintf('slipgaji/%s/%s', $new_dirname, $file);
    

    In the example above, $new_dirname should be '2013/1-2013' and $file should be '2013.05.1557.pdf' to get the URL you're expecting.

    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题