PHP Script fopen failed to open stream: > Invalid argument Error

fopen, php

Solution

Your link IDs have whitespace in them. Try adding `$link = trim($link);` before creating `$link2`.

Problem

I am getting a warning. Warning: fopen(76561197992146126 .txt): failed to open stream: Invalid argument in C:\wamp\www\Download\t3.php on line 6 For anyone wondering, this is the contents of main.txt below (http://pastebin.com/53chSRRz) ``` <?php $APIkey = 'APIKeyHere'; $file = file('C:\wamp\www\Download\main.txt'); foreach ($file as $link) { $link2 = "http://api.steampowered.com/ITFItems_440/GetPlayerItems/v0001/?key=" . $APIkey . "&SteamID=" . $link . "&format=json"; $downloaded = file_get_contents($link2); $fh = fopen($link . ".txt", "a"); //or die("can't open file"); fwrite($fh, $downloaded); } echo "Finished"; ?> ``` If I replace "fopen($link . ".txt", "a")" with a static file-name it works. But I need $link to be the filename. It is imperative to my setup. I am running Windows 7 x64 using WAMP 2.2 with PHP 5.4.3

Original source