Last active
October 13, 2018 07:02
-
-
Save azizultex/cac5648952466dbf7244d5961304eb50 to your computer and use it in GitHub Desktop.
Download or fetch remote image files from base link and file names file_get_contents file_put_contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
"1-big.jpg", | |
"1_01.gif", | |
"1_02.gif", | |
"1_04.gif", | |
"1_05.gif", | |
"1_07.gif", | |
"1_09.gif", | |
"1_11.gif", | |
"2-big.jpg", | |
"3-big.jpg", | |
"4-big.jpg", | |
"5-big.jpg", | |
"1041_1.jpg", | |
"1041_2.jpg", | |
"1041_3.jpg", | |
"1041_4.jpg", | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Curl can be used but needs some processing to get the images names in an array. | |
// $data = wp_remote_get('http://www.perfectpartiesusa.com/wp-content/themes/pparties/images/'); | |
// $body = wp_remote_retrieve_body($data); | |
$allProductImages = include "allProductImages.php"; | |
$baselink = 'http://www.perfectpartiesusa.com/images/'; | |
foreach ($allProductImages as $img_slug) { | |
$image_file = file_get_contents($baselink . $img_slug); | |
$put_link = $_SERVER['DOCUMENT_ROOT'].'/store-images/'.$img_slug; | |
file_put_contents($put_link, $image_file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to collect an array of images file name, you can follow the screenshot below or use curl or wp_remote_get in WordPress. Put all the images names in
allProductImages.php
file.Here are downloaded files:
