Skip to main content
Published: May 03 2011, 6:09:00 PMUpdated: November 28 2020, 1:55:29 PM

file exchange: programmatic code sample

How can i programatically upload files for the FileExchange Service using PHP?

Please refer to the following code sample

 

file exchange: programmatic download code sample

<?php

$token = "...get your own token!...see the comments below..";

/*If you want to upload and download files from eBay you need to get a security token. Your token will be valid for one year, after which you must request another one.get it here ::  https://signin.ebay.com/ws/eBayISAPI.dll?SignIn&runame=F-FILEEXL51P1EHH6L899Q9B969GE134DK-FileUpload*/


$ebay_url = "https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload";

$sendheaders = array(
"User-Agent: ThunderIT.com eBay FE Client v0.1",
);
$fields = array(
"token" => $token,
"file" => "@listing.csv"

/*set the filename as-> $filename = "@listing.csv"; // note that the path is not pertaining to a remoteserver, for some reason only local files seem to work.*/

);

$ch = curl_init($ebay_url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 1); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_NOBODY, 0); // set to 1 to eliminate body info from response
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // use HTTP/1.0 instead of 1.1
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ###
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendheaders);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // use HTTP POST to send form data

$resp = curl_exec($ch); //execute post and get results
curl_close ($ch);

?>

You have to make sure that you php is compiled with the following configure commands:

Configure Command      './configure' '--enable-bcmath' '--enable-calendar' '--enable-dbase' '--enable-exif' '--enable-fastcgi' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-soap' '--enable-sockets' '--enable-sqlite-utf8' '--enable-wddx' '--enable-zip' '--prefix=/usr' '--with-bz2' '--with-curl=/opt/curlssl/' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/opt/openssl' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libexpat-dir=/usr' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mime-magic' '--with-mssql=/usr' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/opt/openssl' '--with-openssl-dir=/opt/openssl' '--with-pcre-regex=/opt/pcre' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--with-pspell' '--with-sqlite=shared' '--with-tidy=/opt/tidy/' '--with-ttf' '--with-unixODBC=/usr' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr'

 

Note: this is a tested configuration, doesnt require all the commands to be enabled. "enabling --with-curl=/opt/curlssl/' " should work.

You can check your current Configure command row from the phpinfo();

 

if you cant find the above commands in your php installation, you can follow the following tutorials.

Clear steps are here:

 http://www.apachefriends.org/f/viewtopic.php?f=17&t=39263&start=0&view=print

and if you are running dev on a windows machine you can refer this
http://www.apachefriends.org/f/viewtopic.php?f=17&t=39263

 

references

Programmatic Uploads and Downloads: A guide for beginners

http://forums.ebay.com/db2/topic/File-Exchange/Programmatic-Uploads-And/520136148

I would suggest looking at the instructions in the documentation here - http://pages.ebay.com/file_exchange/File_Exchange_Advanced_Instructions.pdf

Also you will find some samples here
http://forums.ebay.com/db2/thread.jspa?threadID=1000060674&tstart=40&mod=1141092243080
http://forums.ebay.com/db2/topic/File-Exchange/C-Code-Sample/1000627248&#msg1011537415

I hope this helps. If you have further questions, I suggest you contact the FileExchange customer support - http://contact.ebay.com/ws/eBayISAPI.dll?ContactCS

How well did this answer your question?
Answers others found helpful