Md *_*man 5 php ftp amazon-web-services file-put-contents
$username_ftp = "user";
$password_ftp = "password";
$file_name = "remote-transfer.txt";
$url = "example.biz/test/" . $file_name;
$hostname = "ftp://$username_ftp:$password_ftp@$url";
$content = file_get_contents('index.html');
$options = array('ftp' => array('overwrite' => true));
$stream = stream_context_create($options);
file_put_contents($hostname, $content, 0, $stream);
Run Code Online (Sandbox Code Playgroud)
我尝试将文件从我的远程服务器放到另一台远程服务器,同时从本地主机工作文件中解开此代码,并将文件从我的ocal pc传输到服务器。但是,当我尝试从我的AWS服务器中删除此代码时,它不传输任何文件,当我检查错误日志文件时,它给出了
PHP Warning: file_put_contents(): connect() failed: Permission denied
PHP Warning: file_put_contents(ftp://...@example.biz/remote-transfer.txt): failed to open stream: operation failed in
Run Code Online (Sandbox Code Playgroud)
我的测试 文件夹权限为777, 现在该怎么办,是否有任何服务器配置错过了。
我认为你尝试一下有问题$hostname:(我用我的 ec2 实例尝试了这个解决方案及其工作。)
<?php
/* set the FTP hostname */
$user = "test";
$pass = "myFTP";
$host = "example.com";
//path of file
$file = "test.txt";
$hostname = $user . ":" . $pass . "@" . $host . "/" . $file;
/* the file content */
$content = "this is just a test.";
/* create a stream context telling PHP to overwrite the file */
$options = array('ftp' => array('overwrite' => true));
$stream = stream_context_create($options);
/* and finally, put the contents */
file_put_contents($hostname, $content, 0, $stream);
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1176 次 |
| 最近记录: |