php如何下載文件到指定目錄

PHP
小億
245
2024-03-22 10:31:42

你可以使用file_put_contents()函數(shù)來(lái)下載文件到指定目錄。以下是一個(gè)簡(jiǎn)單的例子:

<?php

$fileUrl = 'http://www.example.com/file.zip';
$savePath = '/path/to/directory/file.zip';

// 下載文件
file_put_contents($savePath, file_get_contents($fileUrl));

echo '文件下載完成';

?>

在上面的例子中,$fileUrl是要下載的文件的URL,$savePath是要保存文件的目標(biāo)目錄。使用file_get_contents()函數(shù)從指定URL獲取文件內(nèi)容,并使用file_put_contents()函數(shù)將文件內(nèi)容保存到指定目錄中。

0