0

我目前使用 ftpwebrequest 将文件从 C# 直接上传到我的服务器。它工作正常。但是,我非常担心将我的 ftp 凭据存储在我的应用程序中 - 所以我想将文件上传到我服务器上的 PHP 文件。

我查看了各种代码示例,但没有一个真正起作用。我喜欢我当前的代码,而其他代码没有提供的是我可以向后台工作人员报告进度。


我找到了这段代码:C#

WebClient web = new WebClient();
            try
            {
                web.UploadFile(Properties.Settings.Default.FtpAddress + "upload1.php", fileToUpload);
            }
            catch (Exception a)
            {
                MessageBox.Show(a.ToString());
            }

PHP:

<?php
//check whether the folder the exists

$connection='ftp.mysite.com';

if(!(file_exists($connection)))
{
  //create the folder
  mkdir($connection);
  //give permission to the folder
  chmod($connection, 0777);
}

//check whether the file exists
if (file_exists($connection. $_FILES["file"]["name"]))
{
  echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
  //move the file into the new folder
  move_uploaded_file($_FILES["file"]["tmp_name"],$connection. $_FILES["file"]["name"]);

}

?>

这里有两件事我需要帮助:首先,我在上传过程中遇到一个异常,说我没有登录。我猜我需要在 php 文件上提供凭据 - 但我无法让它工作.

其次,如何配合后台工作人员汇报进度?

4

0 回答 0