将文件从URL下载到服务器 [英] Download files from url to server
问题描述
我需要PHP代码将文件从一个服务器下载到另一个服务器。它由变量$ HasPrevod定义。这是我需要下载的文件。还有简单的形式,我把链接和输出是变量$ HasPrevod,所以我不得不把它在一个href,以获得链接方便下载。
I need PHP code to download file from one server to another. It's defined by variable $HasPrevod. That's the file which I need to download. Also there's simple form where I put link and the output is that variable $HasPrevod, so I had to put it in a href to get link easily to download.
< a href =$ HasPrevod>下载< / a>。
通过我的服务器上的Filezilla上传。有解决方案,将从该变量下载内容,并将其放在我的服务器上的某个文件夹。我试过cURL,但没有发生,因为我是新手,我犯了shure,我不知道PHP和cURL。
<a href="$HasPrevod">Download</a>.
and download it manually and upload via Filezilla on my server. Is there solution which will download content from that variable and put it on my server in some folder. I tried with cURL but nothing happened because I'm newbie and I've made mistake for shure, and I don't know much about PHP and cURL.
所以应该是这样的$ HasPrevod文件下载 - >我的服务器/文件夹和回显文件名。
So it should be something like this $HasPrevod file download -> my server / folder, and echo file name.
$prevod = $_POST['prevod'];
$url = file_get_contents("$prevod");
$PrevodLink = preg_match('!http://[a-z0-9\S\ \-\_\.\[\]\[\]\/]+\.(?:srt)!Ui', $url, $match1);
$HasPrevod = $match1['0'];
<form action="prevod.php" method="post">
<input name="prevod" type="text"/>
<input type="submit" value="Search"/>
</form>
这是我使用的代码链接和获取位于另一个文件的路径网站不是我自己的,那么我必须手动下载并通过Filezilla在我的服务器上上传。
Thats the code I'm using to put link and get path to the file which is located on another website not my own, then I have to download manually and upload on my server via Filezilla.
<a href= "<?php echo $HasPrevod; ?>">Download</a>
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec ($ch);
curl_close ($ch);
$destination = "prevodi/". $HasPrevod;
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
推荐答案
如果您有足够的权限, $ c> exec('wget http://www.example.com/myFile.zip');
If you have enough permission, try with exec('wget http://www.example.com/myFile.zip');
如果没有,请尝试 file_put_contents()
方法。最后,如果现在工作,尝试 var_dump()
一些状态的代码来调试它。
If not, try with file_put_contents()
method. At last if that now works, try to var_dump()
some states of code to debug it.
这篇关于将文件从URL下载到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!