Last active
August 29, 2015 13:57
-
-
Save juanescalona/9657466 to your computer and use it in GitHub Desktop.
Código para descargar archivos insertados desde los datos de exportación obtenidos en Wordpress.com
This file contains 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 | |
/* Parámetros a modificar */ | |
$data = simplexml_load_file('DATOS_EXPORTADOS_WORDPRESS.XML'); | |
$user = "XXXXXXXXXXXXXX"; | |
$url = "http://$user.files.wordpress.com/"; | |
$total = count($data->channel->item); | |
echo "###########################################################\n\r"; | |
echo " \n\r"; | |
echo " Se han encontrado $total archivos. \n\r"; | |
echo " Iniciando descarga... \n\r"; | |
echo " \n\r"; | |
echo "###########################################################\n\r"; | |
for ($i=0; $i < $total; $i++){ | |
$fileurl = $data->channel->item[$i]->guid; | |
$folder = explode($url,$fileurl); | |
$date = explode("/",$folder[1]); | |
$year = $date[0]; | |
$month = $date[1]; | |
$filename = $date[2]; | |
if (count($date) == 3) { | |
if (!file_exists($year)){ | |
mkdir($year,0777); | |
echo "Creando directorio: /$year \r\n"; | |
} | |
if (!file_exists($year."/".$month)){ | |
mkdir($year."/".$month,0777); | |
echo "Creando directorio: /$year/$month \r\n"; | |
} | |
$path = $year."/".$month."/".$filename; | |
if(!file_exists($path)){ | |
$ch = curl_init($fileurl); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$download = curl_exec($ch); | |
curl_close($ch); | |
file_put_contents($path,$download); | |
echo "Archivo descargado con éxito en: /$path \r\n"; | |
} | |
}else{ | |
echo "Este item no es un archivo de imagen... -> $folder[0] \r\n"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment