Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I download images form Slack, by php or wget

I am trying to download images from a Slack channel by the following code, but I just get the html code of the page.

Am I doing something silly, or they have a trick to make this difficult?

<?php

copy('https://files.slack.com/files-tmb/T1Q3K1TFB-F6TQMM6AG-baba978dff/image003_480.jpg', 'file.jpeg');

echo '<img src="file.jpeg">';
echo '<hr>';

//Get the file
$content = file_get_contents("https://files.slack.com/files-tmb/T1Q3K1TFB-F6TQMM6AG-baba978dff/image003_480.jpg");

//Store in the filesystem.
$fp = fopen("image.jpg", "w");
fwrite($fp, $content);
fclose($fp);
echo '<img src="image.jpg">';
echo '<hr>';

$url_to_image
 = 'https://files.slack.com/files-tmb/T1Q3K1TFB-F6TQMM6AG-baba978dff/image003_480.jpg';

$ch = curl_init($url_to_image);

$my_save_dir = 'images/';
$filename = basename($url_to_image);
$complete_save_loc = $my_save_dir . $filename;

$fp = fopen($complete_save_loc, 'wb');

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo '<img src="'.$complete_save_loc.'">';
echo '<hr>';

echo '<hr><img src="https://files.slack.com/files-tmb/T1Q3K1TFB-F6TQMM6AG-baba978dff/image003_480.jpg">';
echo '<hr><img src="https://files.slack.com/files-tmb/T1Q3K1TFB-F6TQMM6AG-baba978dff/image003_360.jpg">';
echo '<hr><img src="https://conversazioniconmario.slack.com/files/U1Q37UCNL/F6TQMM6AG/image003.jpg">';

?>

wget gets fooled too;

wget -nd -r -P /myLocalPath/images  -A jpeg,jpg,bmp,gif,png https://files.slack.com/files-tmb/T1Q3K1TFB-F6TQMM6AG-baba978dff/image003_480.jpg
like image 734
mario Avatar asked Sep 09 '17 16:09

mario


Video Answer


1 Answers

You can also download file by providing right headers:

 wget -d --header="Authorization: Bearer A_VALID_TOKEN" https://files.slack.com/files-pri/T1Q3K1TFB-F6TQMM6AG-baba978dff/download/image003.jpg
like image 108
Deylo Avatar answered Sep 28 '22 15:09

Deylo