Html href 语法:文件名中是否可以有空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4172579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:16:14  来源:igfitidea点击:

href syntax : is it okay to have space in file name

htmlsyntaxanchorhref

提问by Moon

it has always been my practice that when ever i use images i name them like walls_ico, bu_hover

我一直以来的习惯是,每当我使用图像时,我都会将它们命名为 walls_icobu_hover

so when i give paths they go like

所以当我给出路径时,它们会像

<img src="images/walls_ico.ico" />
<img src="buttons/bu_hover.png" />

UNTIL now when i am on a project where users upload files...

直到现在,当我在一个用户上传文件的项目中时......

i was wondering is it okay to have spaces between file and folders name like

我想知道文件和文件夹名称之间是否可以有空格,例如

<img src="buttons/bu hover.png" />

回答by Frédéric Hamidi

The srcattribute should contain a valid URL. Since space characters are not allowedin URLs, you have to encode them.

src属性应包含有效的 URL。由于URL 中不允许使用空格字符,因此您必须对它们进行编码

You can write:

你可以写:

<img src="buttons/bu%20hover.png" />

But not:

不是

<img src="buttons/bu+hover.png" />

Because, as DavidRR rightfully points out in his comment, encoding space characters as +is only valid in the query string portion of an URL, not in the path itself.

因为,正如 DavidRR 在他的评论中正确指出的那样,将空格字符编码+为仅在 URL 的查询字符串部分有效,而不是在路径本身中有效。

回答by ashish bhatt

If you are using PHP

如果您使用的是 PHP

then find out this code

然后找出这个代码

$result = mysqli_query($con,$sql);
    //echo $ip."<br />";REGEXP
    //echo $name."<br />";
    echo "<table border=2px style='border-radius=20px;' align=center><tr>
    <th>Document ID</th>
    <th>Document Name Type</th>
    <th>Download Documents</th>
    </tr>";//<th>Project Document Type</th>
    while($row = mysqli_fetch_array($result)) {
        $path1=$row['FOLDERNAME'] .'/'. $row['FILENAME'] .'.'. $row['DOCTYPE'];
        $path=str_replace(" ", '%20', $path1);
        echo "<tr>";
        echo "<td>" . $row['DocID'] . "</td>";
       // echo "<td>" . $row['PROJDOCTYPE'] . "</td>";Thank you. Your Apple ID is now ready for use.
        echo "<td>" . $row['DOCNAME'] . "</td>";
        echo '<td><a href=Tender/'.$path.'>'.$row['DOCNAME'].'</a></td>';
        echo "</tr>";
    }
    echo "</table>";

    mysqli_close($con);

回答by Karthik Ratnam

<body>
<img src="file:///C|/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Water lilies.jpg"
</body>

spaces will be allowed only when you are working in local hosts

仅当您在本地主机上工作时才允许使用空格