dounei5721 2015-09-18 23:39
浏览 67

php搜索dir和echo如果存在与否

I have a form with a editbox and a submit button. when someone types something in the editbox, lets say 'hello', the form would then search a directory on the server and echo the result on the page (below the editbox) like this - this directory exists 'or' this directory does not exist

Hope someone can help, any help is very appreciated.

<?php
$dir = 'hello';
if (is_dir($dir)) {
echo "The folder $dir exists";
} else {
echo "The folder $dir does not exist";
}
?>

The above code echo's if the directory 'hello' exists or not, this works fine, I just need it to read from another directory on the server and also from a form, I'm not sure what to place in the 'action' part of the php form for it to recognise and display the query.

Cheers,

  • 写回答

1条回答 默认 最新

  • ds08541 2015-09-19 19:06
    关注

    If your form does a GET request, you can access the value from the $_GET variable.
    If you need to check existence of a folder in another folder, you just need to create a string, that points to that folder.

    <form>
        <input name="dir"/><input type="submit"/>
    </form>
    <?php
        if (isset($_GET['dir'])) // check if value is actually sent
        {
            $dir = $_GET['dir']; // retrieve the value
            if (is_dir('some_folder/'.$dir)) {
                echo "The folder $dir exists";
            } else {
                echo "The folder $dir does not exist";
            }
        }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)