Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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 如果服务器中是否存在文件,则显示和隐藏按钮(href=)_Php_Css_Display - Fatal编程技术网

Php 如果服务器中是否存在文件,则显示和隐藏按钮(href=)

Php 如果服务器中是否存在文件,则显示和隐藏按钮(href=),php,css,display,Php,Css,Display,我试图编辑一个类似的解决方案,但它没有达到预期的效果。我不确定我的编码可能我错了,我使用的是html。是否有一种方法可以隐藏按钮(href=),如果文件存在,则显示是否未找到?谢谢大家! 参考: 然后 然后 另一种方法是向用户提供现有文件的列表,并允许用户从列表中进行选择 <?php // Initialize an empty array $files = []; // Get all the files in a directory (this will also return di

我试图编辑一个类似的解决方案,但它没有达到预期的效果。我不确定我的编码可能我错了,我使用的是html。是否有一种方法可以隐藏按钮(href=),如果文件存在,则显示是否未找到?谢谢大家!

参考:

然后

然后


另一种方法是向用户提供现有文件的列表,并允许用户从列表中进行选择

<?php
// Initialize an empty array
$files = [];

// Get all the files in a directory (this will also return directories)
foreach (glob('*') as $f) {

        // If the item is a file, add it to the files array
        if (is_file($f)) {
                $files[] = $f;
        }
}
?>

<!-- Create a select statement with the files that exist -->
<select id="files">
<!-- Placeholder -->
<option disabled selected>Select file</option>

<!-- Loop through all the files and create options for them -->
<?php foreach ($files as $f) : ?>
<option><?= $f ?></option>
<?php endforeach ?>
</select>

<!-- The button would run the download using the selected file as the source (additional JavaScript required) -->
<button id="go">Download</button>

选择文件
下载

另一种方法是向用户提供现有文件的列表,并允许用户从列表中进行选择

<?php
// Initialize an empty array
$files = [];

// Get all the files in a directory (this will also return directories)
foreach (glob('*') as $f) {

        // If the item is a file, add it to the files array
        if (is_file($f)) {
                $files[] = $f;
        }
}
?>

<!-- Create a select statement with the files that exist -->
<select id="files">
<!-- Placeholder -->
<option disabled selected>Select file</option>

<!-- Loop through all the files and create options for them -->
<?php foreach ($files as $f) : ?>
<option><?= $f ?></option>
<?php endforeach ?>
</select>

<!-- The button would run the download using the selected file as the source (additional JavaScript required) -->
<button id="go">Download</button>

选择文件
下载

哇,太棒了!我将尝试并学习如何实现这一点。非常感谢你!哇,太棒了!我将尝试并学习如何实现这一点。非常感谢你!
<script
              src="https://code.jquery.com/jquery-3.3.1.min.js"
              integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
              crossorigin="anonymous">

</script>
.hidden {
display: none
}
<button type="button" class="hidden" id="test_btn">Download</button>

<script>
$(document).ready(function () {
                $.ajax({
                url: '/path/to/file_checker.php',
                type: 'GET',
                success:function(data){
                var obj = jQuery.parseJSON(data);
                           if(obj.callback == 1) {
                             $('button#test_btn').removeClass('hidden');
                            }
                }
                });
});
</script>
if (file_exists("/aaa/file.txt")) {
    $data = array('callback' => 1);
    echo json_encode($data);
}
else {
    $data = array('callback' => 0);
    echo json_encode($data);
}
<?php
// Initialize an empty array
$files = [];

// Get all the files in a directory (this will also return directories)
foreach (glob('*') as $f) {

        // If the item is a file, add it to the files array
        if (is_file($f)) {
                $files[] = $f;
        }
}
?>

<!-- Create a select statement with the files that exist -->
<select id="files">
<!-- Placeholder -->
<option disabled selected>Select file</option>

<!-- Loop through all the files and create options for them -->
<?php foreach ($files as $f) : ?>
<option><?= $f ?></option>
<?php endforeach ?>
</select>

<!-- The button would run the download using the selected file as the source (additional JavaScript required) -->
<button id="go">Download</button>