I created an application using flickr API + PHP. Somehow my code works in my local machine but when I deploy it onto a server it breaks.
The warning I am getting is:
Warning: Invalid argument supplied for foreach() in /home/u189255383/public_html/imageGallery/imageProcess.php on line 124.
In my code, that part is foreach($resultObj['photos']['photo'] as $photo)
just a code to process the result passed in from the function that gets the result from requesting flickr API.
I found out that it says invalid simply because nothing is in $resultObj
, thats why it's Invalid argument, but I don't get why it's empty.
$url = $request . $method . $sign . $apiKey . $sign . 'text=' . urlencode($input) . $sign . $per_page . $sign . $page . $i . $sign . $format;
$result = file_get_contents($url);
$resultObj = unserialize($result);
This is basically what I did before returning the result. I tried to see if anything inside $result
but turn out that it's already empty at $result
, meaning the file_get_contents($url);
function isn't being executed.
Try using curl. You should check if curl is installed on the remote server:
$url = $request . $method . $sign . $apiKey . $sign . 'text=' . urlencode($input) . $sign . $per_page . $sign . $page . $i . $sign . $format;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$resultObj = unserialize($result);