我正在使用以下代码通过使用 Windows 计划作业将文件自动更新到服务器
<?php
$url="http://example.com/uploadtest";
$p_date = date('Y_m_d');
$files = realpath("../daily_backup/$p_date.txt"); // file name
echo $files;
$data=array();
$data['file']="@".$files;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
print_r ($response);
print_r (curl_getinfo($ch));
echo $response. "Done";
?>
在我上传的最后一页中,代码是
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
move_uploaded_file($_FILES["file"]["tmp_name"],
"xml_data/" . $_FILES["file"]["name"]);
echo "Uploaded";
输出应该是 “上传完成”。但在我的客户端系统中“完成”。*没有错误* 我也检查了路径
但我上面的代码在我的系统中工作。我的客户端系统中缺少什么?.
注意:我在我的客户端系统中使用 xampp。
$ch 的结果是
Array ( [url] => http://example.com/uploadtest [content_type] => [http_code] => 0
[header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [connect_time] => 0
[pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0
[speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1
[starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( )
[primary_ip] => [primary_port] => 0 [local_ip] => [local_port] => 0 [redirect_url] => )