【问题标题】:How to get file using PHP native functions and Android如何使用 PHP 原生函数和 Android 获取文件
【发布时间】:2016-08-12 05:52:34
【问题描述】:

我在我的网站的私人部分做了一个功能,以获取和显示存储库的一些文件。

下面是我做的功能:

function getFilesChantier($devis, $cp) {
        //        Si dossier cp n'existe pas on le créé
        if (!file_exists(_DOCS_ . 'C' . $cp)) {
            mkdir(_DOCS_ . 'C' . $cp, 0777, true);
            fopen(_DOCS_ . 'C' . $cp . '/index.html', w);
        }
        if (!file_exists(_DOCS_ . 'C' . $cp . '/' . $devis)) {
            mkdir(_DOCS_ . 'C' . $cp . '/' . $devis, 0777, true);
            fopen(_DOCS_ . 'C' . $cp . '/' . $devis . '/index.html', w);
        }

        //On liste les fichiers pdf
        $repertoire = _DOCS_ . 'C' . $cp . '/' . $devis;
        if ($dossier = opendir($repertoire)) {
            while (false !== ($fichier = readdir($dossier))) {
                if ($fichier != '.' && $fichier != '..' && $fichier != 'index.php' && $fichier != 'index.html' && $fichier != 'Thumbs.db') {
                    $nb_fichier++; // On incrémente le compteur de 1
                    $retour[$nb_fichier]['name_file'] = str_replace('/var/www/sp-batiment.com/htdocs/docs/C' . $cp . '/' . $devis . '/', '', $repertoire . '/' . $fichier);
                    $retour[$nb_fichier]['url_file'] = str_replace('/var/www/sp-batiment.com/htdocs/', '', $repertoire . '/' . $fichier);
                    $retour[$nb_fichier]['nb_file'] = $nb_fichier;
                    $retour[$nb_fichier]['date_file'] = date("F d Y H:i:s.", filectime($repertoire . '/' . $fichier));
                }
            }
        }
        return $retour;
    }

在所有浏览器中都可以正常工作。

下面是我的网站效果图:

但是当我们使用手机(Android Samsung)时,它无法在 Google Chrome 浏览器上运行,它什么也不显示。

我不知道是我的功能出了什么问题,还是它正在拨打电话?

调用的页面是一样的,只是浏览器变了(第一个是电脑上的经典谷歌浏览器),另一个是三星Galaxy和谷歌浏览器。

编辑

我用的是 Bootstrap,下面是我的表的代码:

<div class="col-md-12">
    <h3>Mes documents</h3>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>#</th>
                <th><i class="fa fa-calendar"></i> Date</th>
                <th class="text-center">Type</th>
                <th>Fichier</th>
                <th>Options</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td nowrap="">1</td>
                <td nowrap="">17-08-2016 </td>
                <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                <td nowrap=""> compément-de-devis-1.pdf</td>
                <td nowrap="">
                    <form action="php/download.php" method="post">
                        <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                    </form>
                </td>
            </tr>
            <tr>
                <td nowrap="">2</td>
                <td nowrap="">04-08-2016 </td>
                <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                <td nowrap=""> autorisation-changement-de-façade.pdf</td>
                <td nowrap="">
                    <form action="php/download.php" method="post">
                        <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                    </form>
                </td>
            </tr>
            <tr>
                <td nowrap="">3</td>
                <td nowrap="">03-08-2016 </td>
                <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                <td nowrap=""> devis-initial.pdf</td>
                <td nowrap="">
                    <form action="php/download.php" method="post">
                        <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                    </form>
                </td>
            </tr>
            <tr>
                <td nowrap="">4</td>
                <td nowrap="">03-08-2016 </td>
                <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                <td nowrap=""> plan-du-batiment.pdf</td>
                <td nowrap="">
                    <form action="php/download.php" method="post">
                        <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                    </form>
                </td>
            </tr>
            <tr>
                <td nowrap="">5</td>
                <td nowrap="">03-08-2016 </td>
                <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                <td nowrap=""> facture-acompte-n-1.pdf</td>
                <td nowrap="">
                    <form action="php/download.php" method="post">
                        <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                    </form>
                </td>
            </tr>
        </tbody>
    </table>                                   
</div>

【问题讨论】:

  • 可以提供html吗?您是否正在使用一些响应式布局(例如引导程序?)如果不查看您的 html,将很难提供帮助。我的猜测是,您的 html 中有一些类可以隐藏表格中的数据,以便在小宽度浏览器(手机)中可见
  • 是的,我确实使用引导程序,我将使用代码进行更新。感谢您的快速回复
  • @StanislasPiotrowski 你能用你的 HTML 更新你的问题吗?
  • Bootstrap 很可能会为您隐藏表格行,因为它在该屏幕尺寸下会很乱。您可能想看看No More Tables 让表格在小屏幕上工作的方法。
  • 尝试在网络浏览器上更改窗口大小,看看会发生什么。 Bootstrap 有多个表选项,您使用的是哪个?除非您提供您的 html,否则您的赏金将得不到任何答案,因为没有人能够正确回答。

标签: php android google-chrome fopen getfiles


【解决方案1】:

在您的 html 代码中没有问题,因为我在移动设备上运行它并且工作正常。

您的代码中有一个小的拼写错误 tex-aligntext-error

您可以通过您的 PC 在您的移动 google chrome 浏览器中检查您的 html 代码。检查此链接

https://developers.google.com/web/tools/chrome-devtools/debug/remote-debugging/remote-debugging?hl=en

从中您可以检查表格行是否从您的 php 代码中膨胀,或者您的 html 代码是否有任何问题

希望这会有所帮助

【讨论】:

    【解决方案2】:

    问题不在于 PHP 代码(它在服务器上解释,而不是在设备上),而在于您的 HTML 或 Javascript 代码。你没有提供它,所以我无法帮助调试。但是您可以尝试在 Chrome 中将窗口大小调整为手机的屏幕大小,您可能会得到相同的结果。同样在桌面 Chrome 中,您可以按 F12,按“切换设备”按钮并选择合适的设备。

    更新:我将您提供的 HTML 代码发布到 jsfiddle(很抱歉在回答中复制了您的代码,但 SO 不允许链接到没有代码的 jsfiddle)。

    <div class="col-md-12">
        <h3>Mes documents</h3>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>#</th>
                    <th><i class="fa fa-calendar"></i> Date</th>
                    <th class="text-center">Type</th>
                    <th>Fichier</th>
                    <th>Options</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td nowrap="">1</td>
                    <td nowrap="">17-08-2016 </td>
                    <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                    <td nowrap=""> compément-de-devis-1.pdf</td>
                    <td nowrap="">
                        <form action="php/download.php" method="post">
                            <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                        </form>
                    </td>
                </tr>
                <tr>
                    <td nowrap="">2</td>
                    <td nowrap="">04-08-2016 </td>
                    <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                    <td nowrap=""> autorisation-changement-de-façade.pdf</td>
                    <td nowrap="">
                        <form action="php/download.php" method="post">
                            <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                        </form>
                    </td>
                </tr>
                <tr>
                    <td nowrap="">3</td>
                    <td nowrap="">03-08-2016 </td>
                    <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                    <td nowrap=""> devis-initial.pdf</td>
                    <td nowrap="">
                        <form action="php/download.php" method="post">
                            <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                        </form>
                    </td>
                </tr>
                <tr>
                    <td nowrap="">4</td>
                    <td nowrap="">03-08-2016 </td>
                    <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                    <td nowrap=""> plan-du-batiment.pdf</td>
                    <td nowrap="">
                        <form action="php/download.php" method="post">
                            <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                        </form>
                    </td>
                </tr>
                <tr>
                    <td nowrap="">5</td>
                    <td nowrap="">03-08-2016 </td>
                    <td nowrap="" class="text-center"><span class="label label-danger" style="text-transform:uppercase;tex-align:left"><i class="fa fa-file-pdf-o"></i></span></td>
                    <td nowrap=""> facture-acompte-n-1.pdf</td>
                    <td nowrap="">
                        <form action="php/download.php" method="post">
                            <button class="btn btn-dark btn-xs"><i class="fa fa-cloud-download"></i> Télécharger</button>
                        </form>
                    </td>
                </tr>
            </tbody>
        </table>                                   
    </div>
    

    它看起来不错,并显示在移动设备上的我的 chrome 中。你确定没有比这个 HTML 更多的东西了吗?例如,除了标准引导程序之外的某种额外的 CSS 和 JS。

    【讨论】:

    • 我确定没有额外的 CSS 或 JS,当我在 chrome 中对答案进行 var_dump 时,我得到了一些东西,但在移动设备中 t 是空的。这是一种奇怪的行为。
    【解决方案3】:

    原因 1:

    您尚未为该 HTML 部分的该输出过程(来自 PHP)提供您的 php 代码。尽管在PHP 中存在检测 BROWSER 的类,但您在输出过程中意外使用它的可能性很小。但是,让我们提供那部分,或者自己检查一下。

    原因 2:

    正如您所说,当“切换”设备时,您会看到它们,这意味着存在 CSS 问题。检查元素是否具有 @media max-width:... 或 overflow:hidden 之类的 css 类/样式或类似它们,这会导致表格被隐藏。

    原因 3:

    虽然您说页面中没有更多代码,但我怀疑可能存在一些 Javascript 代码,这可能会导致问题。很多时候,JS表格是在Page-Load之后动态加载的,可能在设备浏览器中,存在一些问题。 如果您已经共享了您在项目中使用的所有 PHP/HTML 代码,那么发现问题会更容易。

    【讨论】:

      【解决方案4】:

      在您的页面中添加此代码,以便移动用户更清楚

      <style>
      @media 
      only screen and (max-width: 760px),
      (min-device-width: 768px) and (max-device-width: 1024px)  {
      	table, thead, tbody, th, td, tr { 
      		display: block; 
      	}
      	
      	thead tr { 
      		position: absolute;
      		top: -9999px;
      		left: -9999px;
      	}
      	
      	tr { border: 1px solid #ccc; }
      	
      	td { 
      		/* Behave  like a "row" */
      		border: none;
      		border-bottom: 1px solid #eee; 
      		position: relative;
      		padding-left: 50%; 
      	}
      	
      	td:before { 
      		position: absolute;
      		top: 6px;
      		left: 6px;
      		width: 45%; 
      		padding-right: 10px; 
      		white-space: nowrap;
      	}
      	
      	
      	td:nth-of-type(1):before { content: "#"; }
      	td:nth-of-type(2):before { content: "Date"; }
      	td:nth-of-type(3):before { content: "Type"; }
      	td:nth-of-type(4):before { content: "Fichier"; }
      	td:nth-of-type(5):before { content: "Options"; }
      	
      }
      </style>

      【讨论】:

        【解决方案5】:

        我已经在桌面浏览器中检查了您的 html 代码,它工作正常。与桌面一样,我也在测试它的移动视图,表格是响应式的,但由于 Bootstrap,它们的列仍然稳定..

        我得到了您的问题,这不是任何浏览器问题...正确检查您的 html 并将其写入正确的引导 html 表格形式。您只需在 html 上交叉测试所有标签都已关闭的主要内容..

        在移动视图中,一些标签是打开的,但没有关闭,导致此表自身重叠。您只需检查它,在移动视图中.. 我认为它可能发生在 php 循环中(只需检查所有内容)。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-01-17
          • 2018-08-31
          • 1970-01-01
          • 1970-01-01
          • 2012-02-05
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多