Loading


Advertisement:

Author Topic: How to upload images and attach them to a new item  (Read 108 times)

Mansioni 24

  • Newbie
  • *
  • Posts: 4
How to upload images and attach them to a new item
« on: March 28, 2017, 06:25:06 pm »
Hi, i'm trying to create a new item via php using this code:

 $mItems = new ItemActions(false);       
      $your_item = array();
     
      $tit = array();
      $tit['it_IT'] = $title;
      $your_item['title'] = $tit;
     
      $desc = array();
      $desc['it_IT'] = $description;
      $your_item['description'] = $desc;
     
      $your_item['contactName'] = $autor;
      $your_item['contactEmail'] = $post_autor;
      $your_item['active'] = 'ACTIVE';
      $your_item['catId'] = $category;
      $your_item['countryId'] = 'IT';
      $your_item['regionId'] = getRegionIDbyName($region, $your_item['countryId']);
      $your_item['cityId'] = getCityIDbyName($complete_province, $your_item['regionId']);
      $your_item['cityArea'] = $city;
      $your_item['address'] = null;
      $your_item['showEmail'] = 0;
      $your_item['countryName'] = $nation;
      $your_item['regionName'] = $region;
      $your_item['cityName'] = $complete_province;
      $your_item['price'] = $price;
      $your_item['meta_ext-link'] = $link;
     
      $photoData = checkAndDownloadImg($image);

      if ( !empty($photoData) && !empty($photoData['folder']) && !empty($photoData['name']) && !empty($photoData['ext']) ){
         //se l immagine esiste
         $name = array();
         $name['name'] = array($photoData['name']);   
         $type = array();
         $type['type'] = array('image/'.$photoData['ext']);   
         $tmp_name = array();
         $tmp_name['tmp_name'] = array($photoData['folder']);
         $error = array();
         $error['error'] = array(0);
         $size = array();
         $size['size'] = array(30397);
         $your_item['photos'] = array($name, $type, $tmp_name, $error, $size);
      }

      $mItems->data = $your_item;
      $mItems->add();


obviously checkAndDownloadImg() isn't an osclass function so what should i do ?