gpt4 book ai didi

php - 使用 PHP 从远程服务器上传文件到 FTP 服务器

转载 作者:可可西里 更新时间:2023-10-31 22:14:49 25 4
gpt4 key购买 nike

如何使用 PHP 将远程文件从链接(例如 http://site.com/file.zip)上传到 FTP 服务器?我想将“Vanilla Forum Software”上传到服务器,而我的移动数据运营商收费很高,所以如果我可以上传文件而不必从我的手机上传它,我也可以省钱并完成工作。

最佳答案

让你拥有这个功能:

function downloadfile($file, $path) {
if(isset($file) && isset($path)) {
$fc = implode('', file($file));
$fp = explode('/', $file);
$fn = $fp[count($fp) - 1];

if(file_exists($path . $fn)) {
$Files = fopen($path . $fn, 'w');
} else {
$Files = fopen($path . $fn, 'x+');
}
$Writes = fwrite($Files, $fc);
if ($Writes != 0){
echo 'Saved at ' . $path . $fn . '.';
fclose($Files);
}
else{
echo 'Error.';
}

}

}

你可以这样使用它:

downloadfile("http://www.webforless.dk/logo.png","folder/");

希望它运作良好,记得 Chmod 目标文件夹 777。((如果你需要它上传到另一个 FTP 服务器,你可以使用其他评论中发布的 FTP 脚本之一))

最好的问候。乔纳斯

关于php - 使用 PHP 从远程服务器上传文件到 FTP 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8149801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com