php:获取文件内容并将文件存储在特定文件夹中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2729143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php : get file contents and store file in particular folder
提问by Sanjay Khatri
I am getting file contents from the file_get_contents()function in php and I want to store that file in a particular folder. How would I do that?
我正在从file_get_contents()php 中的函数获取文件内容,我想将该文件存储在特定文件夹中。我该怎么做?
$image = file_get_contents('http://www.affiliatewindow.com/logos/1961/logo.gif');
I want to save this image in particular folder.
我想将此图像保存在特定文件夹中。
any idea about it?
有什么想法吗?
回答by Yacoby
$image = file_get_contents('http://www.affiliatewindow.com/logos/1961/logo.gif');
file_put_contents('./myDir/myFile.gif', $image);
回答by Adam Hopkinson
If you're using php 5, you can use file_put_contents:
如果您使用的是 php 5,则可以使用file_put_contents:
file_put_contents('/path/to/file.dat', $data);
file_put_contents('/path/to/file.dat', $data);
回答by Boldewyn
Apart from the mentioned file_put_contents, you could take a look at the example of the fwritefunction.
除了提到的 file_put_contents 之外,您还可以查看fwrite函数的示例。

