【问题标题】:php : get file contents and store file in particular folderphp:获取文件内容并将文件存储在特定文件夹中
【发布时间】:2010-04-28 11:55:49
【问题描述】:

我从 php 中的 file_get_contents() 函数获取文件内容,我想将该文件存储在特定文件夹中。我该怎么做?

$image = file_get_contents('http://www.affiliatewindow.com/logos/1961/logo.gif');

我想将此图像保存在特定文件夹中。

有什么想法吗?

【问题讨论】:

    标签: php file


    【解决方案1】:

    使用file_put_contents()

    $image = file_get_contents('http://www.affiliatewindow.com/logos/1961/logo.gif');
    file_put_contents('./myDir/myFile.gif', $image);
    

    【讨论】:

      【解决方案2】:

      如果你使用的是 php 5,你可以使用file_put_contents:

      file_put_contents('/path/to/file.dat', $data);

      【讨论】:

        【解决方案3】:

        除了提到的file_put_contents,你可以看看fwrite function的例子。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-07-31
          • 2016-03-05
          • 1970-01-01
          • 2022-06-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多