Maison  >  Questions et réponses  >  le corps du texte

PHP如何远程下载txt文件?

网址是:http://dzs.qisuu.com/txt/苏醒的秘密.txt

我再浏览器中打开能够看到网页,有时候会提示我下载

但是php我用file_get_contents()或者curl都下载不了,提示400错误,或者找不到页面

请问这个如何才能下载呢?有的话给个例子,谢谢

ringa_leeringa_lee2721 Il y a quelques jours1490

répondre à tous(2)je répondrai

  • 天蓬老师

    天蓬老师2017-04-11 09:13:53

    那么问题来了。有中文。你得对中文进行urlencode

    $text = urlencode("苏醒的秘密.txt");
    $url  = "http://dzs.qisuu.com/txt/" . $text;
    echo file_get_contents($url);

    répondre
    0
  • ringa_lee

    ringa_lee2017-04-11 09:13:53

    不知能否贴出具体的错误内容,我这边试了一下是可以下载下来的

    file_put_contents('苏醒的秘密.txt', file_get_contents('http://dzs.qisuu.com/txt/%E8%8B%8F%E9%86%92%E7%9A%84%E7%A7%98%E5%AF%86.txt'));

    répondre
    0
  • Annulerrépondre