php - set CURL on template blade laravel

I want to get image from instagram link. the link is thishttps://www.instagram.com/p/B_zZCRpB895/media/?size=t
if you open that link. it will redirect the link into actual image link. The redirect link is this
https://scontent-xsp1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s150x150/95528722_148590620037203_2029915803294658254_n.jpg?_nc_ht=scontent-xsp1-1.cdninstagram.com&_nc_cat=111&_nc_ohc=jeCE5U4ckBkAX8I42Og&oh=79d2aee23705bd88b58801d877642aed&oe=5F22A9C3
that redirect link that i want to capture. and store into DB.
because im using AWS server. i can't get the actual image link from controller. i need to get the link into front end. so i create template blade to get the actual link. i was created file callinstagram.blade.php
and i create this code :
<?php
$image = "https://www.instagram.com/p/B_zZCRpB895/media/?size=t";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $image);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0');
curl_setopt ($ch, CURLOPT_HEADER, TRUE);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
preg_match("|location: (https?://\S+)|", $result, $link);
dump($link[1]);
?>
this code can run well into my local PC.. but when i tried it into my AWS server. it display this execption
Undefined offset: 1 (View: /home/ec2-user/......./views/instagram.blade.php)
how do i solve this?
parameter$link[1]
must return this link
https://scontent-xsp1-1.cdninstagram.com/v/t51.2885-15/e35/c0.180.1440.1440a/s150x150/95528722_148590620037203_2029915803294658254_n.jpg?_nc_ht=scontent-xsp1-1.cdninstagram.com&_nc_cat=111&_nc_ohc=jeCE5U4ckBkAX8I42Og&oh=79d2aee23705bd88b58801d877642aed&oe=5F22A9C3
please help
Answer
Solution:
try{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, 'your header');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode('your fields data'));
$result = curl_exec($ch);
curl_close($ch);
} catch(Exeption $e){
return $e ;
}
return $result ;
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: constant expression contains invalid operations
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.