我在我的网站上的PHP脚本上创建一个.ics文件,现在我在我的计算机本地保存该文件,但我想将其上传到我的iCal Exchange帐户,以便我可以从那里共享它。
我可以通过iCal(应用程序)上传,但我需要通过PHP完成。在iCalExchange中,我有一个用户名和密码,说明如下:
要从iCal发布新日历,请选择“在Web上发布” 服务器“选项,并使用其中一个URL:
http://icalx.com/private/zeroan/
http://icalx.com/public/zeroan/
请务必正确输入新的用户名和密码。
我在PHP中试过没有运气:
$ftp_server='74.91.122.152';//serverip
$conn_id = ftp_connect($ftp_server);
// login with username and password
$user="zeroan";
$passwd="****";
$login_result = ftp_login($conn_id, $user, $passwd);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
die;
} else {
echo "<br>Connected to $ftp_server, for user $user<br>";
}
//directorylike /www.velibaba.com/images
ftp_chdir($conn_id, "http://icalx.com/public/zeroan/");
//$destination_file=ftp_pwd($conn_id);
$source_file='cale.ics';
$destination_file="calendario.ics";
echo ("<br>");
print $destination_file;
echo ("<br>");
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
由于
答案 0 :(得分:1)
完整的工作示例: 我的/var/www/stackoverflow/curluploader.php文件
<?php
$url = "http://localhost/stackoverflow/processupload.php";
$post_data['name'] = "Foo";
$post_data['file'] = '@'.__DIR__ . '/file.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$response = curl_exec($ch);
echo $response;
使用@前缀文件路径可以解决问题。
现在我的/var/www/stackoverflow/processupload.php
<?php
echo "<pre>";
print_r($_POST);
print_r($_FILES);
如果一切正常,你应该这样:
Array
(
[name] => Foo
)
Array
(
[file] => Array
(
[name] => file.txt
[type] => application/octet-stream
[tmp_name] => /tmp/phpEBgYXy
[error] => 0
[size] => 30
)
)
排除proccessupload身份验证,但发送用户和密码的方式与发布字段'name'的方式相同,在proccessupload上做一点认证以保证安全。确保apache用户对远程文件夹具有写权限。