【发布时间】:2012-01-08 12:30:54
【问题描述】:
如何使用php将图片从url上传到ftp?
想把图片从url上传到ftp
例如:http://test.com/imagefile.jpg 或 http://test.com/testvideo.flv
我希望通过 FTP 或 curl php 上传该文件,
我这里有示例代码,但它不起作用。
它说没有找到文件。
$ftp_server ="ftp.yoursite.com"
$ftp_user ="yoursite user"
$ftp_password = "yoursite pass"
$file_to_upload = "http://test.com/imagefile.png";
$remote_location = "/test";
// set up connection or exit with message
$flink = ftp_connect($ftp_server) or exit("Can't connect to ftp server: $ftp_server");
// login or at least try
if(ftp_login($flink, $ftp_user, $ftp_password)) {
// if login successful use ftp_put to upload the file
// if you upload binary files use mode FTP_BINARY
if(ftp_put($flink, $remote_location, $file_to_upload, FTP_ASCII)) {
echo "Success! File is uploaded!";
} else {
echo "Can't upload file";
}
} else {
echo "Can't login with this user & password";
}
// close the connection
ftp_close($flink);
任何人都可以解决这个问题?或者任何人都可以提出比这更好的建议? 谢谢!非常感谢您的帮助。
【问题讨论】:
-
如果您使用 ftp_put,$file_to_upload 必须是服务器上的本地文件。
标签: php file-upload curl upload ftp