mindmaster
Elite Member
- Sep 16, 2010
- 5,668
- 3,110
Anyone know of a plugin/s to accomplish this ?
<?php
// Example JSON file with a link to a .zip file
$json_url = 'path/to/your/json/file.json';
// Fetch the JSON data
$json_data = file_get_contents($json_url);
// Decode JSON data to a PHP array
$data = json_decode($json_data, true);
// Assuming the JSON contains a key with the .zip file URL
$zip_url = $data['zip_file_link']; // Change according to your JSON structure
// Download the .zip file from the URL
$zip_file = 'temp.zip'; // Temporary file to store the downloaded .zip
file_put_contents($zip_file, fopen($zip_url, 'r'));
?>
<?php
$zip = new ZipArchive;
$res = $zip->open($zip_file);
if ($res === TRUE) {
// Specify the extraction path
$extract_to = 'path/to/extract/';
// Extract all contents of the .zip file
$zip->extractTo($extract_to);
$zip->close();
echo 'Zip extracted successfully';
} else {
echo 'Failed to open the zip file';
}
?>
<?php
// Directory where the photos were extracted
$extracted_files_dir = 'path/to/extract/';
// Get all files in the extracted directory
$files = glob($extracted_files_dir . '*.{jpg,png,gif}', GLOB_BRACE);
// Loop through the files and move them to the uploads directory
foreach ($files as $file) {
// Define the destination directory for uploaded photos
$upload_dir = 'path/to/uploads/';
// Move each file to the uploads directory
$file_name = basename($file);
if (rename($file, $upload_dir . $file_name)) {
echo "Successfully uploaded: " . $file_name . "<br>";
} else {
echo "Failed to upload: " . $file_name . "<br>";
}
}
?>