简体   繁体   English

使用PHP将文件下载到我的服务器目录

[英]Download a file to my server directory using PHP

my system uses a XML file generated by a URL and I need a script that every 30 minutes access that URL ( https://www.shopfisio.com.br/feeds/teste-leo?download=true ), and download the file to my server directory. 我的系统使用URL生成的XML文件,并且我需要一个脚本,该脚本每30分钟访问该URL( https://www.shopfisio.com.br/feeds/teste-leo?download=true ),然后下载该文件到我的服务器目录。

Can somebody help me how to do this? 有人可以帮我怎么做吗?

In a simple case you can use following code: 在简单的情况下,您可以使用以下代码:

<?php

    $xml = file_get_contents('https://www.shopfisio.com.br/feeds/teste-leo?download=true');
    file_put_contents('import.xml', $xml);

For scheduling execution of your script you might use cron . 为了计划脚本的执行,可以使用cron

You can create a cron job entry that run a script every 30 minutes. 您可以创建一个cron作业条目,该条目每30分钟运行一次脚本。 In the script you should use CURL , Or just use package like guzzle to create a request to the url and save the returning body into a file on your server by one of read&write like file_put_contents files functions in php, hope thats help you. 在脚本中,您应该使用CURL ,或者仅使用guzzle之类的包来创建对url的请求,并通过php中诸如file_put_contents文件功能的读写功能之一将返回的正文保存到服务器上的文件中,希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM