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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With