views:

170

answers:

2

Hello all,

I think I know the answer for this question allready, but just as curious I am, I'll ask it anyways.

I'm running a webshop which products come with a csv file. I can import all the objectsng without any trouble, the only thing is that images and thumbnail locations are not exported with the the database dump. (it's never perfect heh) You might say, do it manually then, that's what I did in the first place, but after 200 products and RSI, I gave it up and looked for a better more efficient way to do this.

I have asked my distributer and I can use their images for my own goals without any having copyright problems.

When I look at the location of the images, the url looks like this:

../img/i.php?type=i&file=1250757780.jpg

Does anyone have a idea how this problem can be tackled?

For scraping a website, I found this code:

<?php
function save_image($pageID) {

    $base = 'http://www.gistron.com';

    //use cURL functions to "open" page
    //load $page as source code for target page

    //Find catalog/ images on this page
    preg_match_all('~catalog/([a-z0-9\.\_\-]+(\.gif|\.png|\.jpe?g))~i', $page, $matches);

    /*
    $matches[0] => array of image paths (as in source code)
    $matches[1] => array of file names
    $matches[2] => array of extensions
    */

    for($i=0; $i < count($matches[0]); $i++) {
        $source = $base . $matches[0][$i];
        $tgt = $pageID . $matches[2][$i];    //NEW file name. ID + extension

        if(copy($source, $tgt)) $success = true;
        else $success = false;
    }

    return $success; //Rough validation. Only reports last image from source
}


//Download image from each page
for($i=1; $i<=6000; $i++) {
    if(!save_image($i)) echo "Error with page $i<br>";
}
?>

For some reason it throws this error: Error with page 1, Error with page 2, etc

A: 

Well, you can either make the distributer to give you the image names in the CSV file and then you can construct the URLs directly, or you will have to scrap their website via a script and fetch the images (I'd ask them for permission before doing this).

Lukáš Lalinský
Thanks, they are ok with this, I will cal them tomorrow for more info about these images.
Chris
A: 

That URL doesn't really tell you where the picture is located - only that a script i.php will be called and the file name is passed in as a parameter file on the query string.

Where the i.php script goes to actually find the image cannot be deduced from just the info you present here. You'd have to inspect the script to find out that information, me thinks.

marc_s