×

php读取文件夹名称下拉列表

php读取文件夹名称下拉列表(php读取目录及子目录下所有文件名的方法)

admin admin 发表于2023-03-26 20:06:09 浏览42 评论0

抢沙发发表评论

本文目录一览:

PHP里怎么获取下拉列表的value

PHP 可以通过表单GET、POST、jquery ajax 等获取到下拉列表的值

例如:POST 方式

form name="form1" method="post" action="index.php?action=ok"

select name="contents"

option value="1"1/option

option value="2"2/option

option value="3"3/option

/select

input type="submit" value="提交"

/form

?php

if($_GET['action'] == 'ok'){

$contents = $_POST['contents'];

echo $contents;

}

?

例如:GET 方式

form name="form1" method="get" action="index.php?action=ok"

select name="contents"

option value="1"1/option

option value="2"2/option

option value="3"3/option

/select

input type="submit" value="提交"

/form

?php

if($_GET['action'] == 'ok'){

$contents = $_GET['contents'];

echo $contents;

}

?

例如: jquery ajax 方式

script language="javascript"

function check(value){

$.ajax({

url:'ajax.php?action=ok',

type:'post',

data:'value='+value,

async : false,

success: function(){

}

});

}

/script

select name="contents" onclick="check(this.value);"

option value="1"1/option

option value="2"2/option

option value="3"3/option

/select

ajax.php 文件

?php

if($_GET['action'] == 'ok'){

$value = $_POST['value'];

echo $value;

}

php获取文件夹下所有文件名

function dir_file_handle($dir,$dir_handle,$file_handle,$array=NULL) {

$array = array();

function circle($dir,$dir_handle,$file_handle,$array){

$handle=opendir($dir);

while(($file=readdir($handle))!==false){

if($file!="." $file!=".."){

if(is_dir("$dir/$file")){

//文件夹操作

eval($dir_handle);

circle("$dir/$file",$dir_handle,$file_handle,$array);

}else{

//文件操作

eval($file_handle);

}

}

}

}

@circle($dir,$dir_handle,$file_handle,$array);

}

function list_dir_file($array) {

$indent = 0;

static $preindent = 0;

while (list($key,$value) = each($array)) {

$indent = count(explode('/', $key));

if ($indent == 1) {

$indent = $preindent;

}else {

$preindent = $indent;

}

$dirname = substr(strrchr($key, '/'), 1);

if (is_array($value)) {

echo str_repeat("  ", $indent)."|-$dirnamebr";

list_dir_file($value);

}else {

echo str_repeat("  ", $indent*2)."$valuebr";

}

}

}

dir_file_handle(

'./01',

'

if(is_null($array["$dir"])) {

$array["$dir"] = array();

}

if(is_null($array["$dir/$file"])) {

$array["$dir/$file"] = array();

}

',

'array_push($array["$dir"],$file);',

$array

);

list_dir_file($array);

php获取下拉列表框的值

js、ajax实现

seelect id="one"/select!--第一个下拉框--

seelect id="two"/select!--第二个下拉框--

script

$(function(){

    $('#one').on('chenge', function(){

        var val = $(this).val();

        $.get('查找第二个下拉框的方法', {'val' : val}, function(arr){

            var text = 'option请选择option';

            // 返回一个带有第二个下拉框的json串

            $.each(arr, function(i ,o){

                text += 'option value="' + o.value + '"' + o.title + 'option';

            })

            $('#two').empty().append(text);

        })

    })

})

/script

PHP下拉表单菜单

1、新建一个php文件,命名为test.php,用于讲解PHP实现下拉表单菜单。

2、在test.php文件内,使用html中的select标签创建下拉菜单,代码如下。

3、在test.php文件内,使用option标签创建一个提示选项“请选择职业”。

4、在test.php文件内,在select标签内,创建一个php数组,在数组中存储三个不同的职业名称。

5、在test.php文件内,使用foreach遍历上一步创建的数组$arr,每次遍历的数组值为$v。

6、在test.php文件内,使用echo输出option菜单,option菜单的value值和选项名称都为$v。

7、在浏览器运行test.php文件,查看实现的效果。

php 获取当前目录所有文件夹名 及下级目录文件夹名 求代码详解

把这个文件放到\wamp\www\ 这里,然后运行。

?php

if (isset($_GET['dir'])){ //设置文件目录

$basedir=$_GET['dir'];

}else{

$basedir = '.';

}

checkdir($basedir);

function checkdir($basedir)

{

if ($dh = opendir($basedir)) {

while (($file = readdir($dh)) !== false) {

if ($file != '.' $file != '..'){

if (!is_dir($basedir."/".$file)) {

echo "filename: $basedir/$file br";

}else{

$dirname = $basedir."/".$file;

checkdir($dirname);

}

}

}

closedir($dh);

}

}

?

[以下于为题无关]

吗蛋,代码前的空格都没了,这不是我去掉的哦,是百X把空格全去了,有强迫症表示不能接受啊...........

PHP如何遍历指定文件夹,获取所有文件列表并生成下载链接??

试编写代码如下:

?php

$dir="D:/WWW/ftp"; //指定的路径

$sitepath = '';

//遍历文件夹下所有文件

if (false != ($handle = opendir ( $dir ))) {

    echo "$dir 目录下的文件列表:BR/";

    $i = 0;

    while (false !== ($file = readdir($handle))) {

        if ($file != "."  $file != ".."  !is_dir($dir.'/'.$file)) {

            echo 'a href="' . $sitepath . $file . '"'.$file. '/abr/';

        }

    }

    //关闭句柄

    closedir($handle);

}

?

代码中需要提示的是:

如果是运行于互联网上,需要考虑文件的访问安全性。

运行截图: