通过PHP表单上传FTP [英] FTP upload via PHP form

查看:95
本文介绍了通过PHP表单上传FTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过FTP上载文件上传文件。

 < html> 
< body>
< form enctype =multipart / form-dataaction =upload_file.phpmethod =POST>
< input type =hiddenname =MAX_FILE_SIZEvalue =100000/>
选择要上传的文件:< input name =uploadedfiletype =file/>< br />
< input type =submitvalue =Upload File/>
< / form>
< / body>
< / html>

以下是PHP文件:

 <?php 

$ ftp_server =xxx;
$ ftp_username =xxx;
$ ftp_password =xxx;

//建立连接
$ conn_id = ftp_connect($ ftp_server)或死(无法连接到$ ftp_server);

// login
if(@ftp_login($ conn_id,$ ftp_username,$ ftp_password))
{
echoconectd as $ ftp_username @ $ ftp_server\ N;
}
else
{
echo无法连接为$ ftp_username\\\
;
}

$ file = $ _FILES [file] [name];
$ remote_file_path =/home/www/lifestyle69/import/\".$file;
ftp_put($ conn_id,$ remote_file_path,$ file,FTP_ASCII);
ftp_close($ conn_id);
echo\\\
\\\
connection closed;

?>

FTP连接成功连接,但文件无处。



任何人都可以帮助我吗?

谢谢!

解决方案

因为您有< input name =uploadedfiletype =file/>

  $ file = $ _FILES [file] [name]; //错误
$ file = $ _FILES [uploadedfile] [name]; // right

由于您需要PHP存储的临时副本的文件名,该副本存在于服务器上:

  ftp_put($ conn_id,$ remote_file_path,$ file,FTP_ASCII); //错误
ftp_put($ conn_id,$ remote_file_path,$ _FILES [uploadedfile] [tmp_name],
FTP_ASCII); // right

请参阅 PHP文档了解更多关于$ _FILES的信息。


I want to upload a file via FTP upload in a form.

<html>
  <body>
    <form enctype="multipart/form-data" action="upload_file.php" method="POST">
      <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
      Choose a file to upload: <input name="uploadedfile" type="file" /><br />
      <input type="submit" value="Upload File" />
    </form>
  </body>
</html>

Here is the PHP file:

<?php

$ftp_server = "xxx";
$ftp_username   = "xxx";
$ftp_password   =  "xxx";

// setup of connection
$conn_id = ftp_connect($ftp_server) or die("could not connect to $ftp_server");

// login
if (@ftp_login($conn_id, $ftp_username, $ftp_password))
{
  echo "conectd as $ftp_username@$ftp_server\n";
}
else
{
  echo "could not connect as $ftp_username\n";
}

$file = $_FILES["file"]["name"];
$remote_file_path = "/home/www/lifestyle69/import/".$file;
ftp_put($conn_id, $remote_file_path, $file, FTP_ASCII);
ftp_close($conn_id);
echo "\n\nconnection closed";

?>

The FTP connection connects successfully but the file is nowhere.

Can anybody help me?

Thanks!

解决方案

Because you have <input name="uploadedfile" type="file" />:

$file = $_FILES["file"]["name"]; // wrong
$file = $_FILES["uploadedfile"]["name"]; // right

Because you need the filename of the temporary copy stored by PHP, which exists on the server:

ftp_put($conn_id, $remote_file_path, $file, FTP_ASCII); // wrong
ftp_put($conn_id, $remote_file_path, $_FILES["uploadedfile"]["tmp_name"],
        FTP_ASCII); // right

Refer to the PHP documentation for more information about $_FILES.

这篇关于通过PHP表单上传FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆