我有一个带有URL的文件!
$url = "http://www.example.com/aa.txt";
我想下载此文件并将其保存到我网站上的路径
这是我的网站 ( 在线 (
$path = "server/username/";
我希望将$url
文件保存到$path
,,
我试试这个
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>
当我测试代码时,它使文件下载到我的计算机而不是我的网站
您可以使用file_put_contents();
请参阅手册:http://php.net/manual/en/function.file-put-content.php
这里有一个不同的实现:http://www.finalwebsites.com/forums/topic/php-file-download