Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP Get访问具有特殊字符的目录_Php - Fatal编程技术网

使用PHP Get访问具有特殊字符的目录

使用PHP Get访问具有特殊字符的目录,php,Php,我尝试使用PHP制作简单的图像库,自动检测文件夹中的所有图像,下面是我的代码 <?php $dirname = rawurlencode($_GET['dir']); $images = glob($dirname."*.jpg"); foreach($images as $image) { echo '<img src="'.$image.'" /><br />';

我尝试使用PHP制作简单的图像库,自动检测文件夹中的所有图像,下面是我的代码

<?php 
    $dirname = rawurlencode($_GET['dir']);
    $images = glob($dirname."*.jpg");
    
    foreach($images as $image) {
        echo '<img src="'.$image.'" /><br />';
    }
我很确定我的代码是有效的,因为在使用另一个文件夹之前我已经尝试过了(但没有特殊字符,例如:kamen rider new),但是如果文件夹有特殊字符,它就不起作用,如何解决

如果我不使用脚本(直接通过浏览器)和php脚本进行访问,就会出现这种情况

工作

http://localhost/simpleAlbum/%5bnewAlbum%5d%20Kamen%20Rider%20--Special%20Gallery%204.1/
不起作用

http://localhost/simpleAlbum/swipe.php?dir=%5bnewAlbum%5d%20Kamen%20Rider%20--Special%20Gallery%204.1
顺便说一句,有很多文件夹具有特殊字符,如果我从所有文件夹中删除所有特殊字符,这很复杂,因为我制作了另一个脚本来自动清除相册


谢谢

您必须使用
urlencode
对可能包含特殊字符的URL进行编码。我尝试过rawurlencode/urlencode,但它不起作用,伙计!您不能对要传递到
glob
的内容进行URL编码!任何使用真实文件系统的东西都必须具有真实的字符。您仅在创建URL时使用
urlencode
,顾名思义。
http://localhost/simpleAlbum/swipe.php?dir=%5bnewAlbum%5d%20Kamen%20Rider%20--Special%20Gallery%204.1