• <small id='VsLwv'></small><noframes id='VsLwv'>

  • <legend id='VsLwv'><style id='VsLwv'><dir id='VsLwv'><q id='VsLwv'></q></dir></style></legend>
  • <tfoot id='VsLwv'></tfoot>

  • <i id='VsLwv'><tr id='VsLwv'><dt id='VsLwv'><q id='VsLwv'><span id='VsLwv'><b id='VsLwv'><form id='VsLwv'><ins id='VsLwv'></ins><ul id='VsLwv'></ul><sub id='VsLwv'></sub></form><legend id='VsLwv'></legend><bdo id='VsLwv'><pre id='VsLwv'><center id='VsLwv'></center></pre></bdo></b><th id='VsLwv'></th></span></q></dt></tr></i><div id='VsLwv'><tfoot id='VsLwv'></tfoot><dl id='VsLwv'><fieldset id='VsLwv'></fieldset></dl></div>

          <bdo id='VsLwv'></bdo><ul id='VsLwv'></ul>

        在 PHP 中显示最近从远程 FTP 服务器上传的图像

        时间:2023-10-30
          <tbody id='xarwb'></tbody>

        <small id='xarwb'></small><noframes id='xarwb'>

          • <i id='xarwb'><tr id='xarwb'><dt id='xarwb'><q id='xarwb'><span id='xarwb'><b id='xarwb'><form id='xarwb'><ins id='xarwb'></ins><ul id='xarwb'></ul><sub id='xarwb'></sub></form><legend id='xarwb'></legend><bdo id='xarwb'><pre id='xarwb'><center id='xarwb'></center></pre></bdo></b><th id='xarwb'></th></span></q></dt></tr></i><div id='xarwb'><tfoot id='xarwb'></tfoot><dl id='xarwb'><fieldset id='xarwb'></fieldset></dl></div>

              <bdo id='xarwb'></bdo><ul id='xarwb'></ul>
            • <tfoot id='xarwb'></tfoot>
              • <legend id='xarwb'><style id='xarwb'><dir id='xarwb'><q id='xarwb'></q></dir></style></legend>

                  本文介绍了在 PHP 中显示最近从远程 FTP 服务器上传的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  最近,我创建了一个上传表单,用户可以在其中将他们的文件上传到远程 FTP 服务器.到现在为止,一切都很顺利.但是,我有一个问题.

                  Recently, I have created an upload form in which users can upload their files to a remote FTP server. Until now, everything is going well. However, I have a problem.

                  我想确保当用户将他的图片上传到远程 FTP 服务器时,该图片将立即显示在网站上.我怎样才能做到这一点?这个问题在 Stack Overflow 上被问了很多.然而还是有区别的.在大多数情况下,个人希望从远程 FTP 服务器下载特定文件.我不是这种情况.我想确保用户看到他上传的文件显示在网站上.

                  I want to make sure that when the user his image is uploaded to the remote FTP server, the image will be displayed immediately on the website. How can I do this? This question has been asked a lot on Stack Overflow. Yet there is a difference. In most cases, the individual wanted to download a specific file from the remote FTP server. This is not the case with me. I want to make sure that the user sees the file he uploaded displayed on the site.

                  我将文件上传到远程 FTP 服务器的 php 代码:

                  My php code for uploading a file to the remote FTP server:

                  <?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
                  }
                  
                  $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 connection
                  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 the file
                  $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
                  // check upload status
                  if (!$upload) { 
                  //
                  } else {
                  ?>
                  <meta http-equiv="refresh" content="0; url=https://radioprogrammabank.nl/wp/upload-album/?name=<?php echo urlencode(basename($_FILES['file']['name']));?>">
                  <?php
                  echo "<a href="$source_file?file=".urlencode($source_file)."">".htmlspecialchars($source_file)."</a>";
                  header('Content-Type: application/octet-stream');
                  echo file_get_contents('ftp://username:password@ftp.example.com/path/' . $_GET["file"]);
                  
                  echo "upload is gelukt";
                  }
                  
                  // close the FTP stream 
                  ftp_close($conn_id);
                  ?>
                  

                  推荐答案

                  FTP上传成功后,需要将用户浏览器重定向到查看器页面.

                  Once the FTP upload succeeds, you need to redirect user's browser to a viewer page.

                  header("Location: view.php?name=".urlencode(basename($_FILES['file']['name'])));
                  

                  view.php 中,使用示例中的代码从远程 FTP 服务器下载特定文件".或查看列出并从 FTP 下载点击的文件.

                  In the view.php, use the code from your examples to "download a specific file from the remote FTP server". Or see List and download clicked file from FTP.

                  请注意,要使 Location 标头正常工作,您之前不能输出任何内容 - 因此没有 echo 也没有 HTML 代码.

                  Note that for the Location header to work, you cannot output anything before – so no echo and no HTML code.

                  但是由于您没有独立的 PHP 代码,而是从某个 WordPress 插件中执行它,因此 WordPress 甚至在您的代码开始之前就已经输出了一些 HTML 标头.所以重定向不起作用.

                  But as you do not have a standalone PHP code, but you executed it from within some WordPress plugin, the WordPress will have already outputted some HTML headers before your code even starts. So the redirect won't work.

                  在 WordPress 开发 Stack Exchange 上有一个关于此的问题:
                  wp_redirect() 无法在 WordPress 中插入 PHP 插件.
                  你问过另一个人:
                  错误:无法修改标头信息"

                  There's a question on this on the WordPress development Stack Exchange:
                  wp_redirect() not working in Insert PHP plugin in WordPress.
                  And you have asked another one:
                  Error: "Cannot modify header information"

                  或者作为一个蹩脚的黑客,你可以尝试元重定向:

                  Or as a lame hack, you can try meta redirect:

                  <meta http-equiv="refresh" content="0; url=view.php?name=<?php echo urlencode(basename($_FILES['file']['name']));?>">
                  

                  这篇关于在 PHP 中显示最近从远程 FTP 服务器上传的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:删除 FTP 连接上的文件夹和所有文件 下一篇:FTP 连接太多,无法接受更多

                  相关文章

                  <legend id='ea8hH'><style id='ea8hH'><dir id='ea8hH'><q id='ea8hH'></q></dir></style></legend>
                    <bdo id='ea8hH'></bdo><ul id='ea8hH'></ul>

                1. <small id='ea8hH'></small><noframes id='ea8hH'>

                2. <i id='ea8hH'><tr id='ea8hH'><dt id='ea8hH'><q id='ea8hH'><span id='ea8hH'><b id='ea8hH'><form id='ea8hH'><ins id='ea8hH'></ins><ul id='ea8hH'></ul><sub id='ea8hH'></sub></form><legend id='ea8hH'></legend><bdo id='ea8hH'><pre id='ea8hH'><center id='ea8hH'></center></pre></bdo></b><th id='ea8hH'></th></span></q></dt></tr></i><div id='ea8hH'><tfoot id='ea8hH'></tfoot><dl id='ea8hH'><fieldset id='ea8hH'></fieldset></dl></div>

                    1. <tfoot id='ea8hH'></tfoot>