浏览器不会显示新文件 - PHP

我正忙于修复每次显示文件时都会显示点的错误。修复错误后,点不再显示,而是显示我上传的第一个文件。但是,当我想上传新文件时,它不显示。旧文件仍保留在那里(应显示两个文件)。


我曾经Continue修复过显示的点。


我的 PHP 代码:


<?php


if ( empty( $_FILES['file'] ) ) {

?>

<html>

  <head>


  </head>

  <body>

    <form action="" enctype="multipart/form-data" method="post">

      <input name="file" type="file"/>

      <br>

      <input name="submit" type="submit" value="Upload uw album" />

    </form>

  </body>

</html>

<?php

return;

} else {

?>

<html>

  <head>

  </head>

  <body>

    <form action="" enctype="multipart/form-data" method="post">

      <input name="file" type="file"/>

      <br>

      <input name="submit" type="submit" value="Upload uw album" />

    </form>

  </body>

</html>

<?php

}


// Connectiegegevens

$ftp_server = "myserver";

$ftp_user_name = "myuser";

$ftp_user_pass = "mypass";

$source_file = $_FILES['file']['tmp_name'];

$destination_folder = "/public_html/wp/wp-content/plugins/AbonneerProgrammas/Albums";

$destination_file = $destination_folder . "/" . basename($_FILES['file']['name']);

$conn_id = ftp_connect($ftp_server);

// login with username and password

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

ftp_pasv($conn_id, true); 



// check connectie

if ((!$conn_id) || (!$login_result)) { 

    echo "Het spijt ons, er is momenteel geen connectie met de server.";

    // echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 

    exit; 

} else {

     // echo "upload is gelukt";

}


// upload het bestand

$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

// check upload status 

if (!$upload) { 

echo "Er is iets fout gegaan, excuses voor het ongemak";

} else {


// weergeef het bestand & download

$contents = ftp_nlist($conn_id, $destination_folder);


   foreach ($contents as $mp3_url) { 

    $filename = basename($mp3_url, ".mp3");

// Dit zorgt ervoor dat de punten niet te zien zijn

    if($filename == "." && "..") {

    continue;

    print_r($filename);

   }



    }

?>

https://img1.mukewang.com/64edc2c8000156d409460261.jpg


湖上湖
浏览 101回答 1
1回答

函数式编程

您正在使用 foreach 循环来获取数据:foreach ($contents as $mp3_url) {&nbsp;&nbsp; &nbsp; $filename = basename($mp3_url, ".mp3");// Dit zorgt ervoor dat de punten niet te zien zijn&nbsp; &nbsp; if($filename == "." && "..") {&nbsp; &nbsp; continue;&nbsp; &nbsp; print_r($filename);&nbsp; &nbsp;}但是这样您只显示该循环最后一次迭代的结果:&nbsp; &nbsp;<tr>&nbsp; &nbsp; &nbsp;<td><?php echo "<a href='$mp3_url'>$filename</a>"; ?></td>&nbsp; &nbsp;</tr>尝试:$filenames = [];foreach ($contents as $mp3_url) {&nbsp;&nbsp; &nbsp; // {...} your remaining code&nbsp; &nbsp; $filenames[] = $mp3_url;}进而foreach ($filenames as $filename) {&nbsp; &nbsp; echo $filename;}将这些文件名存储在数组中而不是字符串中将使您能够迭代它们。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5