-
Notifications
You must be signed in to change notification settings - Fork 76
/
index.php
65 lines (40 loc) · 1.41 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
set_time_limit(0);
date_default_timezone_set('UTC');
require __DIR__.'/vendor/autoload.php';
//////////////////////
//////////////////////
/////// CONFIG ///////
require 'config.php';
$debug = true;
$truncatedDebug = true;
//////////////////////
//////////////////////
//////////////////////
function download_img_from_url($imgurl , $photopath) {
$fileName = "$photopath";
$fileUrl = "$img_url";
$ch = curl_init($fileUrl); // set the url to open and download
$fp = fopen($fileName, 'wb'); // open the local file pointer to save downloaded image
curl_setopt($ch, CURLOPT_FILE, $fp); // tell curl to save to the file pointer
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // tell curl to follow redirects
curl_exec($ch); // fetch the image and save it with curl
curl_close($ch); // close curl
fclose($fp); // close the local file pointer
}
download_img_from_url($img_url, $photoFilename);
$ig = new \InstagramAPI\Instagram($debug, $truncatedDebug);
try {
$ig->login($username, $password);
} catch (\Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."\n";
exit(0);
}
try {
$metadata = ['caption' => "$image_description"];
$ig->timeline->uploadPhoto($photoFilename, $metadata);
echo "Upload Done!" ;
} catch (\Exception $e) {
echo 'Something went wrong: '.$e->getMessage()."\n";
}
?>