Hey Girls & Boys,
I'm currently importing data with some basic scraping from another page and adding new pages with the ProcessWire API.
The data is mostly text which works fine but some images can't get downloaded from the other page.
My guess would be due to the filename.
Here's the Error:
ProcessWire\WireException
File could not be downloaded (https://************.com/content/v1/5e8119f5232766b98/1613689-FJ73MYGC/Außenansicht+2+Galerie.jpg) 400 Bad Request: (tried: curl) search
My Code snippet (throws the error also without sanitizer):
if($html->find('img.thumb-image', 0)->{'data-src'}) {
$image = $html->find('img.thumb-image', 0)->{'data-src'};
$p->article_thumb = $sanitizer->url($image);
}
Is there a way to do this?
Thanks for your time ?
Edit: Found a solution. urlencode changed the whole URL and made the API upload empty images. So I kept the URL until the last slash and just changed the filename like so:
$image = $html->find('img.thumb-image', 0)->{'data-src'};
$imageURL = $image;
$pos = strrpos($imageURL, '/') + 1;
$result = substr($imageURL, 0, $pos) . urlencode(substr($imageURL, $pos));