[英]php how download file from url and save it on server
我的鏈接 (URL) 不同!!! 並且不適用於通常的方法我認為因為網站加載 js 或 aspx 你可以在你的瀏覽器中測試我的鏈接(URL)並看到下載開始但不能在 php 中工作
我已經測試了所有方法(fetch、curl、file、get、put),但它不起作用。 我這里有一個類似的 URL:'http://www.tsetmc.com/tsev2/data/ClientTypeAll.aspx?h=0&r=0'
我可以在瀏覽器中打開它並下載一個 csv 文件我需要在 php 中執行此操作並將 csv 文件保存在服務器上
到目前為止,這是我嘗試過的:
<?php
$file = fopen('http://www.tsetmc.com/tsev2/data/ClientTypeAll.aspx?h=0&r=0');
$file = file_get_contents('http://www.tsetmc.com/tsev2/data/ClientTypeAll.aspx?h=0&r=0');
file_put_contents('ClientTypeAll.csv', $file);
?>
我不要內容!!! 如果你在瀏覽器中測試我的鏈接,我想要一個 csv 文件從你的電腦開始下載
我使用遠程 PDF 文件運行此代碼。
<?php
$url = 'https://example.com/file.pdf';
$dir_name = 'storage-x'; // saVe the directory name
if (!file_exists($dir_name)) {
mkdir($dir_name, 0777, true);
}
$path = $dir_name.'/'.rand().'.pdf';
$file = file_get_contents($url);
file_put_contents($path, $file);
?>
請按照以下步驟操作。
請檢查以下對我有用的示例。
<?php
$file = file_get_contents('https://example.com/file.pdf');
$dirName = 'storage-pdf';
if (!file_exists($dirName)) {
mkdir($dirName, 0777, true);
}
$newFilePath = $dirName.'/'.rand().'.pdf';
file_put_contents($newFilePath, $file);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.