1
I have a pack of images in a folder that works like this: nome-do-produto-m.jpg
, for average size.
Now I want to download the big size.
I made a code to read images from the local directory, change the letter of m
for g
and download the new images. Apparently it works, but the images come all with size 0kb
.
My code:
<?php
$path = "arquivos/";
$diretorio = dir($path);
echo "Lista de Arquivos do diretório '<strong>".$path."</strong>':<br />";
while($arquivo = $diretorio -> read()){
//echo "<a href='".$path.$arquivo."'>".$arquivo."</a><br />";
$fotogrande = str_replace('-m.', '-g.', $arquivo);
//echo $fotogrande;
$url = "www.site.com.br" . $fotogrande;
$ch = curl_init($url);
$fp = fopen('fotogrande/'. $fotogrande, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
$diretorio -> close();
?>
Example of Valid URL generated by my script: https://www.site.com.br/product/14667-sal-temperado-gostinho-alho-e-sal-200g-g.jpg
can we chat? I don’t understand what you mean, because if I give an echo on the line, it’s riding the right way
– Ricardo Gonçalves
@Ricardogonçalves Arrives more on chat: https://chat.stackexchange.com/rooms/90925/downloading-imagens-de-um-site-com-php
– LipESprY
function that is a doja :P
– Ricardo Gonçalves
@Ricardogonçalves Taking PHP to the extreme, right?! Kkkkk
– LipESprY