WebClient UploadFile到PHP $ _FILES?

时间:2019-06-21 17:24:56

标签: c# php upload

我正在使用C#WebClient()将文件上传到CentOS主机上的PHP,如下所示:

<body class="homeBG blur" style="padding-top: 100px">
<div class="rain">
<div class="container-fluid">
  <div class="row">
    <section class="homepageHeading col-xl-10 offset-xl-1">I like baseball</section>
  </div>
</div>
</div>

</body>

我有两台使用上面完全相同的代码的计算机,因此它们都将相同的schFile发送到PHP $ _FILES,但是我可以通过_mach_name和_localIP分辨出哪台计算机。

我接收此文件的PHP代码如下:

            using (WebClient wc = new WebClient())
            {
                NameValueCollection parameters = new NameValueCollection();
                parameters.Add("computer", _mach_name);
                parameters.Add("ipadr", _localIP);
                wc.QueryString = parameters;

                byte[] bret = wc.UploadFile(url, "POST", schFile);
                string sret = Encoding.ASCII.GetString(bret);
            }

}

上面的代码可以正常工作几个月-然后最近开始选择以前上传的旧文件而不是最近上传的文件?那么,它会在旧的过时的上载文件和新的正确的刚刚上载的文件之间切换吗?我不知道为什么要这样做,任何人都可以帮忙吗?这是我从file_put_contents(...)进行的调试

$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'schedule';
date_default_timezone_set('America/Los_Angeles');
$time = strtotime(" ");
$time = date("M,d,Y h:i:s A");

$test = print_r($_FILES, true);

if (!empty($_FILES)) {
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
    $name = $_GET['computer'];  //get the computer name so I know if this is the north or south side schedule
    $ipadr = $_GET['ipadr'];    //get the computer ip address - another way to tell whos schedule this is
    file_put_contents("upload_schedule_debug.txt", "time: $time   name: $name   ip: $ipadr    _FILES:  $test\r\n", FILE_APPEND);

    $error = $_FILES['file']['error'];
    if($error == UPLOAD_ERR_OK) {
        $tempFile = $_FILES['file']['tmp_name'];
        $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;

        //Add computer name to front of schedule filename - ie SV-North-PC_player_schedule.db3 / SV-South-PC_player_schedule.db3
        $filename = $name . "_" . $_FILES['file']['name'];
        $targetFile =  $targetPath . $filename;
        move_uploaded_file($tempFile, $targetFile);
        //$_FILES = array();  //clear the $_FILES
    }
}

0 个答案:

没有答案