G
G
Guyler2015-08-22 12:19:24
CMS
Guyler, 2015-08-22 12:19:24

Can you help me edit the code for the file import module in cms opencart?

It is necessary to finalize the module, so that every time it imports a product, it creates a new folder in a certain directory and uploads pictures there with the date and time of loading. I purchased the mod from the internet. The trouble is that it loads all the pictures in one folder and this is very bad. And it would be desirable that at each import the new folder would be created.
If I'm right, then this is the part of the code that is responsible for this. I can reset the entire code. Help plz.

public function fetchImage($image_url, $folder='') {
    if (strpos($image_url, 'http') !== 0) {
      return '';
    }
    
    if($folder != '') {
      $new_folder = DIR_IMAGE . 'data/' . $folder;
      if (!file_exists($new_folder)) {
        mkdir($new_folder, 0777, true);
      }
    }
    
    if (strstr($image_url, '?')) {
      if($folder != '') {
        $filename = 'data/' . $folder . '/' . md5($image_url) . '.jpg';
      } else {
        $filename = 'data/' . md5($image_url) . '.jpg';
      }
    } else {
      $url_parts = explode('/', $image_url);
      
      if($folder != '') {
        $filename = 'data/' . $folder . '/' . end($url_parts);
      } else {
        $filename = 'data/' . end($url_parts);
      }
      
    }
    if (!file_exists(DIR_IMAGE . $filename)) {
      $fp = fopen(DIR_IMAGE . $filename, 'w');
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $image_url);
      curl_setopt($ch, CURLOPT_FILE, $fp);
      curl_exec($ch);
      $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);
      fclose($fp);
      $file_info = getimagesize(DIR_IMAGE . $filename);
      if($httpCode == 404 || empty($file_info) || strpos($file_info['mime'], 'image/') !== 0) {
        unlink(DIR_IMAGE . $filename);
        $filename = '';
      }
    }
    return $filename;
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2015-08-24
@scherbuk

i.e. you have $this->fetchImage('vasya.jpg') somewhere,
you need to change it to $this->fetchImage('vasya.jpg', 'folder')
then the pictures will fall into /data/folder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question