file_get_contents failed to open stream : invalid argument with URL

时间:2015-07-29 00:14:24

标签: php

I am trying to get details for bans on a Steam user account using the file_get_contents function in PHP. However, it keeps erroring and I have no idea why:

     for result in resultsAsArray {

                if let resultDict = result as? NSDictionary {

                    let cell = UITableViewCell(style: .Value1, reuseIdentifier: "identifer")
                    cell.textLabel?.text = resultDict.objectForKey("name") as? String

                    let id = (resultDict.objectForKey("productId") as! String).toInt()!
                    cell.tag = id

                    cell.imageView?.image = UIImage(named: "placeholder")

                    let image = request(.GET,
                        "http://www.website.com/\(id).png").response() {

                        (_, _, data, _) in

                            println("loading image for \(id)")

                            let image = UIImage(data: data! as NSData)
                            cell.imageView!.image = image

                    }

                    products.append(cell)

                    (view.viewWithTag(1) as! UITableView).reloadData()

                }

            }

The error is as follows:

$detailURL = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=3C11B751BB59DEEE28D744C0A8BAC2EC&steamids=76561198078737264");
$profile = file_get_contents($detailURL);
$buffer = fopen("coOn4LxnQm/{$steamIDpost}.json", "w+");
fwrite($buffer, $profile);
fclose($buffer);

$steam = json_decode(file_get_contents("coOn4LxnQm/{$steamIDpost}.json"));

If you have any idea, please help me. No idea what "failed to open stream: Invalid argument" means and googling and such did not help much.

Thanks.

1 个答案:

答案 0 :(得分:3)

After this line

$(document).foundation();
$("#myModal").on("opened.fndtn.reveal", function(){
  console.log("this should log");
});

$detailURL = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=3C11B751BB59DEEE28D744C0A8BAC2EC&steamids=76561198078737264"); will now contain the result from the API (a JSON String)

If you have a look at this line:

$detailURL

This line is doing a file_get_contents on a JSON String, and it has no sense.