drnysdnnb2909701 2017-03-23 21:56
浏览 91
已采纳

在文件名中显示带空格的图像(php)

I'm going through the images I have in the img folder, and all of the images show up fine except for the ones that have spacing in their names e.g. "Screen shot.png". The user can upload photos, and their files may have spaces in the file name. Should I just remove all spaces before I save the images into my img folder? Or is there a way to still display the images with spacing in the image filepath?

function displayImage($row) {
                    $file_path = "img/" . $row['File_name'];
                    $image_title = $row['Title'];
                    echo "<br>" . $file_path;
                    echo "<li><img src=$file_path alt=$image_title>";
                    echo "<span class='info'><span>$image_title</span></span></li>";
                }
  • 写回答

5条回答 默认 最新

  • douang4294 2017-03-23 22:05
    关注

    Use rawurlencode()...

    function displayImage($row) {
        $file_path = "img/" . rawurlencode($row['File_name']);
        $image_title = $row['Title'];
        echo "<br>" . $file_path;
        echo "<li><img src=$file_path alt=$image_title>";
        echo "<span class='info'><span>$image_title</span></span></li>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了