加载页面时,PHP代码无法启动

时间:2017-10-25 15:56:48

标签: php

我制作了下面的代码来显示用户插入的文件,但是它只显示了附加文件后的文件,但我希望它在加载页面时显示,以便用户查看他的文件已上传。这是我用来上传文件的代码:

<center><p class="text-success" style="font-size: 20px; padding-bottom: 100px;">
  <?php
  session_start();
  require_once('conecta.php');
  $email = $_SESSION['email'];
  if (isset($_POST['enviar'])) {
    $arq = $_FILES['arquivo']['name'];
    $dataup = date('Y-m-d H:i:s');
    echo $dataup;

    $arq = str_replace(" ", "_", $arq);
    $arq = str_replace("ç", "c", $arq);

    if (file_exists("uploads/".$arq)) {
      $a = 1;

      while (file_exists("uploads/[".$a."]".$arq)) {
        $a++;
      }

      $arq = "[".$a."]".$arq;
    }

    if (move_uploaded_file($_FILES['arquivo']['tmp_name'], 'uploads/'.$arq)) {
      $objDb = new db();
      $link = $objDb->conecta_mysql();
      $sql = "insert into arquivos (email_vol, nomearq) values ('".  $email."', '".$arq."')";
      if (mysqli_query($link, $sql)){
        echo 'Plano de aula 1 enviado com sucesso!';
      } else {
        echo (mysqli_error($link));
        echo 'Erro ao enviar o plano de aula!';
      }

    } else {
      echo "Nenhum arquivo selecionado!";
    }

  }
  ?>
</p></center>

以下是在页面上显示文件的代码:

<?php
       session_start();
       require_once('conecta.php');
       $pasta = "uploads/";
       $consulta = mysqli_query($link, "SELECT * FROM arquivos WHERE email_vol = '$email'");
        while ($resultado = mysqli_fetch_array($consulta)) {
            echo "<a href=\"" . $pasta . $resultado["nomearq"] . "\">" . $resultado["nomearq"] . "</a><br />";
        } 
?>

有人可以帮我一把吗?非常感谢你提前。

0 个答案:

没有答案