亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

瀏覽器不會顯示新文件 - PHP

瀏覽器不會顯示新文件 - PHP

PHP
呼啦一陣風 2022-10-28 09:15:29
我正忙于修復每次顯示文件時都會顯示點的錯誤。修復錯誤后,點沒有顯示,它顯示了我上傳的第一個文件。但是,當我要上傳新文件時,它不會顯示。舊文件仍然存在(應顯示兩個文件)。我曾經Continue修復顯示的點。我的PHP代碼:<?phpif ( 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><?phpreturn;} 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 connectieif ((!$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);   }    }?>
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

您正在使用 foreach 循環來獲取數據:


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);

   }

但是,您只顯示該循環的最后一次迭代的結果:


   <tr>

     <td><?php echo "<a href='$mp3_url'>$filename</a>"; ?></td>

   </tr>

嘗試:


$filenames = [];

foreach ($contents as $mp3_url) { 

    // {...} your remaining code

    $filenames[] = $mp3_url;

}

接著


foreach ($filenames as $filename) {

    echo $filename;

}

將這些文件名存儲在數組中而不是字符串中將使您能夠迭代它們。


查看完整回答
反對 回復 2022-10-28
  • 1 回答
  • 0 關注
  • 162 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號