我通过$ _GET传递文件夹名称和路径。一切都很好,直到我传递包含和(&)&符号的文件夹名称,然后文件夹名称被缩短。即文件夹名称测试&替换被缩短为'测试'。 尝试过str_repalce,htmlentites,htmlspecialchars
$dir_path = $_GET['path'].$_GET['folder'];
整个代码:
<div class="panel-body" style="font-size:14px">
<?php
if(isset($_GET['path'])){
$dir_path = $_GET['path'].$_GET['folder']."/";
echo "full path = ".$dir_path."<br>folder = ".$Folder;
}else{
$dir_path = PUBLICPATH."/Folderholder/".$branch."/"; // branch url to that branchs folders and in $_GET['folder'];
}
//$dir = opendir($dir_path);
$mappath = str_replace(PUBLICPATH."/Folderholder/","",$dir_path);
echo "<p><i class='fa fa-sitemap'> <b>".$mappath."</b></i></p>\n"; ?>
<div class="row">
<div class="col-md-6">
<?php
echo "<button onclick='goBack()' class='btn btn-primary btn-sm'>Return</button><P>\n";
?>
</div>
<div class="col-md-6">
<?php
if(parent::$UM->get('Level') !== 'User' and $branch !== 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}elseif(parent::$UM->get('Level') == 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}
?>
</div>
</div>
<div class="row"><div class="col-md-12"> </div></div>
<table width="70%">
<?php
$files = scandir($dir_path);htmls
foreach ($files as $file)
{
if($file != "." && $file != "..")
{
echo "<tr>\n";
if(is_dir($dir_path.$file)){
echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".$file."'>$file</a></td>\n";
echo "<td> </td>\n";
}else{
echo "<td><i class='fa fa-download'></i> ".$file."</td>\n<td><a href='http://downloadfolder/download1.php?file=".$dir_path.$file."' target='_Blank'>Download</a></td>\n";
}//change path as required
echo "</tr>\n";
}
}
?>
</table>
</section>
</div>
答案 0 :(得分:1)
&
字符用于分隔查询字符串中的键=值对。
生成查询字符串时,应将其表示为转义序列:%26
。
如何执行此操作取决于您首先生成查询字符串的方式。
您已标记此php,但您共享的PHP代码读取数据。您没有向我们展示生成它的代码,但假设 仍然是PHP:
要在PHP中生成它,通常会使用http_build_query
:
$query = http_build_query(Array( path => "example&example", folder => "example&example" ));
答案 1 :(得分:0)
urlencode
应该做到这一点。它专门用于将参数传递给URL以用作变量,就像在GET中一样。
答案 2 :(得分:0)
虽然此帖子中的先前答案不正确,但请考虑使用rawurlencode,因为它会生成更符合标准的RFC 3986)URI。 urlencode触发传统编码,其中空格被加号替换。 (有人记得吗?)
答案 3 :(得分:0)
停止剪切文件夹名称。 两个编码更改$ dir_path = $ _GET [&#39;路径&#39;]。$ _ GET [&#39;文件夹&#39;]。&#34; /&#34 ;;改为
$dir_path = $_GET['path'].rawurldecode($_GET['folder'])."/";
和echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".$file."'>$file</a></td>\n";
改为
echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".rawurlencode($file)."'>$file</a></td>\n";
<div class="panel-body" style="font-size:14px">
<?php
if(isset($_GET['path'])){
$dir_path = $_GET['path'].$_GET['folder']."/";
}else{
$dir_path = PUBLICPATH."/Folderholder/".$branch."/"; // branch url to that branchs folders and in $_GET['folder'];
}
//$dir = opendir($dir_path);
$mappath = str_replace(PUBLICPATH."/Folderholder/","",$dir_path);
echo "<p><i class='fa fa-sitemap'> <b>".$mappath."</b></i></p>\n"; ?>
<div class="row">
<div class="col-md-6">
<?php
echo "<button onclick='goBack()' class='btn btn-primary btn-sm'>Return</button><P>\n";
?>
</div>
<div class="col-md-6">
<?php
if(parent::$UM->get('Level') !== 'User' and $branch !== 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}elseif(parent::$UM->get('Level') == 'Main-Admin'){
echo "<a href='uploadfrm?path=".$dir_path."' class='btn btn-primary btn-sm'>Upload to this folder</a>";
}
?>
</div>
</div>
<div class="row"><div class="col-md-12"> </div></div>
<table width="70%">
<?php
$files = scandir($dir_path);htmls
foreach ($files as $file)
{
if($file != "." && $file != "..")
{
echo "<tr>\n";
if(is_dir($dir_path.$file)){
echo "<td><i class='fa fa-folder'></i> <a href='".BASEURL."Folderholder/userdash?path=".$dir_path."&folder=".$file."'>$file</a></td>\n";
echo "<td> </td>\n";
}else{
echo "<td><i class='fa fa-download'></i> ".$file."</td>\n<td><a href='http://downloadfolder/download1.php?file=".$dir_path.$file."' target='_Blank'>Download</a></td>\n";
}//change path as required
echo "</tr>\n";
}
}
?>
</table>
</section>
</div>
答案 4 :(得分:-1)
使用urlencode
对网址进行编码,如:
$encodedURL = urlencode ('Your url');
说明:urlencode
会将特殊字符编码为其实体值,而不是使用它。