I'cant Download Image of post from Facebook - image

I use the api graph and obtain an image the type:
https://scontent.xx.fbcdn.net/v/t1.0-9/s720x720/27972193_10209727361415594_5326795209597866457_n.jpg?oh=680574d073b0e54d60ed86f9143b05f0&oe=5B1CC7DD
The, I use this code por download the image:
$link_curl = curl_init($image);
curl_setopt($link_curl, CURLOPT_RETURNTRANSFER, true);
$bytes_image = curl_exec($link_curl);
curl_close($link_curl);
$image_name=date("YmdHis")."jpg";
$file = fopen( $directory_local . $image_name,'w');
fwrite($file,$bytes_imagen);
fclose($file);
The result is a file empty.
Help Please

Related

How to store image as URL in Laravel 8.*

In my application I add photos that are then scaled, I call them to my views using {{asset()}}
Everything works fine, but for my mobile app I need to send to API URL of image instead of just image path called from db.
That's how I save images now:
$image = $request->photo_patch;
$filename = time() . '.' . $image->extension();
$event->photo_patch = $filename;
$image_resize = Image::make($image->getRealPath());
$image_resize->resize(1200, 630);
$image_resize->save('storage/images/' . ($filename));
$event->save();
Example of saved image name:
1630531230.jpg
That's how I get image on view:
<img src="{{ asset('storage/images/' . $eventView->photo_patch) }}">
What I tried:
$url = Storage::url($filename);
$event->photo_patch = $url;
After this file name looks like this
"/storage/1631043493.png"
But that isnt really URL
What can I do to save photo path like this:
"localhost/storage/images/1631043493.png"
Edit:
# Фарид Ахмедов suggested to call whole URL in API.
How can I do that then?
This is what I tried:
Route::get('/events/{id}', function($id){
return [
Event::findOrFail($id),
'image' => asset('storage/images/'.$this->photo_patch)
];
});
That's it.
url(Storage::url($filename));
But I think, you don't need to save the whole path. You can convert it to full URL before sending response.

Full youtube palylist using curl ( only half list is dispalying using normal curl )

click to check how the list is loading
i am using the following code to curl youtube but it is showing only top 100 videos in playlist how can i show full playlist videos. There are 180 videos in playlist
( i know about API but i want to use this without youtube API)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.youtube.com/playlist?list=PL1FO3JrU9Zy-A-q8s4FdzgzNVWsIcTx5q');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$contents = curl_exec ($ch);
echo $contents;
curl_close ($ch);
?>
Which procedure should i follow to get the full playlist ?
I have got my answer.
I need to curl the remaining videos by
Firstly Gather information like url, parameters and request type (post/get) from that ajax request.( by clicking on inspect and the click on network leaflet)
Generate the same request from your php/curl code and you got it.

Codeigniter Curl

I am new to CI. I am uploading file from a url(drop box file chooser) but now its uploading to the root directory. I want to know how I can give path to file upload inside the CURL functions.
below is the code .
$curl = curl_init($url);
$file = fopen(basename($url), 'wb');
$file_name =(basename($url));
curl_setopt($curl, CURLOPT_FILE, $file);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_exec($curl);
curl_close($curl);
fclose($file);
Thank you.
That is not possible to set file upload path on curl functon direct.
Please use of drop box api library in codeigniter link below.
drop box api :- https://github.com/jimdoescode/CodeIgniter-Dropbox-API-Library
and follow step.

Laravel 5.1 Snappy pdf image not rendering in pdf file

I am using barryvdh/laravel-snappy to generate pdf file. I have two image files 1. yourlogohere.png is in public/image/ folder and 2. logo2.png is in folder other than public i.e. storage/app/logo and to get this file I defined a route (www.example.org/logo/logo.png) and use following code to access it.
public function logo($filename)
{
$file = Storage::disk('local_logo')->get($filename);
$mime = 'image/png';
return (new Response($file, 200))->header('Content-Type', $mime);
}
Problem:
When I use following code to generate pdf from the html containing the first file, pdf contains the yourlogohere.png image
$snappy = App::make('snappy.pdf');
$html='<img src="http://www.example.org/images/yourlogohere.png" class="img-responsive" alt="Your Logo Here">';
$snappy->generateFromHtml($html, $path,[],$overwrite = true);
But when I do exact same thing for the second file, pdf does not render the image.(When I open the link http://www.example.org/logo/logo2.png in browser I get the image). What am I missing?
$snappy = App::make('snappy.pdf');
$html='<img src="http://www.example.org/logo/logo2.png" class="img-responsive" alt="Your Logo Here">';
$snappy->generateFromHtml($html, $path,[],$overwrite = true);
Thanks,
K
You can also do:
<img src="data:image/jpeg;base64,
{{ base64_encode(#file_get_contents(url('your.image.url'))) }}">
I think I got the what the problem is, the route to access the image is via auth, even when user is logged in while accessing the snappy, the wkhtmltopdf exe runs in a shell that is totally different session. Now the right fix would be to be embed the image in the html that is sent to snappy instead of the link, Which I am not sure how I will do? Any suggestions welcome there.
Update:
I as able to convert the image to data:image/png;base64, and embed it in html.
$html = view('mytemplate.default', compact('variable1', 'variable2'))->render();
/*Convert logo image to base64 before pdf conversion*/
//search for <img src="http://example.org/mytemplate/logo/logo1.png">" and replace the src with data:image/png;base64,
$search = '/(<img\s+src=["\'])([^"\']+)(\/mytemplate\/logo\/)(.*)(\.)(.*?)(["\']\s+[^>]+>)/';
$html = preg_replace_callback($search, function ($matches) use ($invoicedetail) {
$filename = $matches[4] . $matches[5] . $matches[6];
$file = Storage::disk('local_logo')->get('yourlogohere.png');
$mime = "image/png";
$mytemplate = MyTemplate::where('logo_filename', '=', $filename)->first();
if (!empty($mytemplate)) {
$file = Storage::disk('local_logo')->get($mytemplate->logo_filename);
$mime = $mytemplate->logo_mime;
}
$base64 = 'data:' . $mime . ';base64,' . base64_encode($file);
return $matches[1] . $base64 . $matches[7];
}, $html);
$pdf_filename = 'template' . $mytemlpate->id . '.pdf';
$path = storage_path('app' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $filename);
$snappy = App::make('snappy.pdf');

Display Cross-domain feed RSS in Wordpress site

I need to display cross-domain feeds-rss (XML format)in my site, but i get a error because ajax cross-domain call are not allowed. I've been told about json-p...anyone knows how to use or have some good tutorial?
Thanks
the simplest way is just to create an widget for wordpress or download some kind of like your requirement.
Because json-p load data in JSON format if you want to get data from JSON format then the given link will help you :
getJSON
ajax
or you can access the rss feed with php like given example :
$xml = 'http://blog.webtech11.com/feed';
$doc = new DOMDocument();
$doc->load($xml);
$item = $doc->getElementsByTagName('item');
//$data = array();
for($i=0; $i<=3; $i++){
$title = $item->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
$link = $item->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
echo '<h2>' . $title . '</h2>';
}
in this example i access latest 4 blog entries..
hope this will help you

Resources