You are here:  » merchant logo and brand logo url attachment script

Support Forum



merchant logo and brand logo url attachment script

Submitted by sbedigital on Mon, 2012-01-30 16:30 in

hi Dave,

just wondering, whether it is possible modify the merchant logo part of the script in admin section. at the moment, i can only upload the merchant logo from my own computer, can this be modified to fetch the image from any given URL? i.e rather than uploading from my computer, lot of affiliate network has the URL for merchant logo, so i can input the URL in location box then the script downloads it to /logo/ folder stores it with correct name.

this would be even better if you can make the script to read a flat data file where all logo URL stored, then download the logos to the server once processed.

also can similar technique applied for brand logos as well?

it's becoming real frustration for me as i have hunt around to download logos from various network?

even though the current process lot easier, what it used to be, but when you have several hundred merchants, that becomes lot harder as you need to download them individually, then upload them as you pairing with each merchants.

thanks for time.

noor

Submitted by support on Mon, 2012-01-30 17:28

Hello Noor,

Updating by feed is complicated by the fact that there would have to be a direct 1-1 mapping between merchant name used in the feed and merchant name as registered on your site; however uploading feed by URL is much more straight forward.

I'll check this out on my test server and follow up by email for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by sbedigital on Mon, 2012-01-30 21:12

How about creating tab delimited text file, I.e merchant name, logo url. Once file is created, I upload somewhere on the server. Then script downloads all logo pair them with relevant merchant.

Submitted by support on Tue, 2012-01-31 09:36

Hello Noor,

That would be more realistic. Let's say you maintain the feed as logos.txt in your feeds folder, with the following format:

Merchant 1,http://www.example.com/logos/merchant1.jpg
Merchant 2,http://www.example.com/logos/merchant2.jpg

etc., in other words a comma (or you could use tab if you wish) separated list of Merchant Name followed by logo URL.

Have a go with the following (designed to run from the /scripts/ folder) for exmaple:

scripts/fetchlogos.php

<?php
  
require("../includes/common.php");
  
$fp fopen($config_feedDirectory."logos.txt","r");
  while(!
feof($fp))
  {
    
$line trim(fgets($fp,1024));
    if (
$line)
    {
      
$parts explode(",",$line);
      
$merchant $parts[0];
      
$url $parts[1];
      
copy($url,"../logos/".$merchant);
    }
  }
?>

- If using tab separated values, use "\t" in place of "," in the explode() function

- This version uses a simple copy() call which will require that PHP's URL wrappers are enabled; if this isn't available then it could be re-written to use cURL

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sbedigital on Tue, 2012-01-31 19:50

I'll try that later on and post the feedback in due course. this will be a popular addition for any new releases as this will lot of work.

Submitted by idea12 on Thu, 2012-04-19 17:11

Hallo David,

Your script is really great and everything is working for my website. But I have one question regarding the scripts/fetchlogos.php issue posted here: http://www.pricetapestry.com/node/4468.

I want to fetch the merchant logos using the fetchlogos.php script, but the copy() call is not working for me, i.e. the PHP's URL wrappers are not enabled. And I have no idea how to rewrite it in cURL. Could you help me with this?

Kind regards

Submitted by support on Thu, 2012-04-19 19:24

Hello idea12, thank you for your comments and welcome to the forum!

The equivalent code to the above but using cURL would be:

<?php
  
require("../includes/common.php");
  
$fp fopen($config_feedDirectory."logos.txt","r");
  while(!
feof($fp))
  {
    
$line trim(fgets($fp,1024));
    if (
$line)
    {
      
$parts explode(",",$line);
      
$merchant $parts[0];
      
$url $parts[1];
      
$ch curl_init($url);
      
curl_setopt($chCURLOPT_HEADER);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$img curl_exec $ch );
      
$fp fopen("../logos/".$merchant,"w");
      
fwrite($fp,$img);
    }
  }
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by idea12 on Fri, 2012-04-20 07:06

Good Morning David,

Thank you for the fast answer.

I have tried the code above, but got an error:

"Internal Server Error / The server encountered an internal error or misconfiguration and was unable to complete your request."

I forgot to mention that the path to the image in my case is in this format:

Merchant 1,http://banners.webmasterplan.com/view.asp?&site=6461&b=20

and not with .jpg in the end.

Perhaps this is the reason, why it is not working??

Submitted by support on Fri, 2012-04-20 08:03

Hi,

Whilst it shouldn't cause Internal Server Error my apologies the original code was inconsistent with regards to file locations, I have modified the below to intend to be run from the main Price Tapestry installation folder, so you would have:

featchlogos.php
feeds/logos.txt
logos/

The logos directory must be created and writable, the easiest way to double check that is
normally via your FTP program. In the remote window, right-click on the folder and look for Permissions... or maybe Properties... and then Permissions. Then give WRITE access to all users - Owner / Group / World.

I also added fclose() which should have been in place - corrected version as below;

<?php
  
require("includes/common.php");
  
$fp fopen($config_feedDirectory."logos.txt","r");
  while(!
feof($fp))
  {
    
$line trim(fgets($fp,1024));
    if (
$line)
    {
      
$parts explode(",",$line);
      
$merchant $parts[0];
      
$url $parts[1];
      
$ch curl_init($url);
      
curl_setopt($chCURLOPT_HEADER);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$img curl_exec $ch );
      
$fp fopen("logos/".$merchant,"w");
      
fwrite($fp,$img);
      
fclose($fp);
    }
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by idea12 on Fri, 2012-04-20 11:23

Hi David,

It's working now. Thank you very much!

Best wishes