下载文件、更改扩展名并合并为 1 个文件
尝试通过 URL 下载文件,将 .ADM 扩展名重命名为 .txt 然后将每个文件的内容放入一个txt文件中 然而它说 fputs 参数 2 是一个资源 $logfile['name'] 是存储在数组中的文件名
这是我的代码
foreach($items as $logfile)
{
$getfile = $logfile['Download'];
$newfile = file_put_contents(str_replace('ADM','txt',$logfile['name']),
file_get_contents($getfile));
$name = str_replace('ADM','txt',$logfile['name']);
$newfile = $name;
$file = fopen($newfile, 'rb');
$output = fopen('tmp/test.txt', 'wb');
fputs($output, $file);
fclose($output);
fclose($file);
}
它下载每个文件并重命名,但是它不移动内容和内容给我这个错误
Warning: fputs() expects parameter 2 to be string, resource given in
Trying to download files via the URL, rename from the .ADM extension to .txt
then put contents of each file into a single txt file
However its saying the fputs param 2 is a resource
The $logfile['name'] is the filename thats stored in the array
Heres my code
foreach($items as $logfile)
{
$getfile = $logfile['Download'];
$newfile = file_put_contents(str_replace('ADM','txt',$logfile['name']),
file_get_contents($getfile));
$name = str_replace('ADM','txt',$logfile['name']);
$newfile = $name;
$file = fopen($newfile, 'rb');
$output = fopen('tmp/test.txt', 'wb');
fputs($output, $file);
fclose($output);
fclose($file);
}
Its downloading each and renaming however its not moving the content & giving me this error
Warning: fputs() expects parameter 2 to be string, resource given in
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fputs
的第二个参数是文件的内容。不是文件资源。而不是
Youll need to get the content of the file
或者,如果您喜欢使用
fopen
,您可以使用fread
:然后您可以将此内容放入另一个文件中:
The second parameter of
fputs
is the content of a file. Not a file resource.Instead of
You‘ll need to get the contents of the file
Or, if you like to use
fopen
, you can usefread
:Then you can put this content into another file: