Jump to content

Saving XML feed


sonicthehedgehog

Recommended Posts

I'm trying to parse an XML file to a database but before I do that I need to convert the URL into an XML file. I'm able to create a file on the server but the file it does write is all gibberish. I've attached a screenshot of what I get.

This is the code I'm using to write the file:
<?phpset_time_limit(0);$fp = fopen ('a.xml', 'w+');$ch = curl_init('http://datafeed.api.productserve.com/datafeed/download/apikey/099640af374a1c61137ad9b60f202215/fid/3712/columns/aw_product_id,merchant_product_id,merchant_category,aw_deep_link,merchant_image_url,search_price,description,product_name,merchant_deep_link,aw_image_url,merchant_name,merchant_id,category_name,category_id,delivery_cost,currency,store_price,display_price,data_feed_id,rrp_price,specifications,condition,promotional_text,warranty,merchant_thumb_url,aw_thumb_url,brand_name,brand_id,delivery_time,valid_from,valid_to,web_offer,pre_order,in_stock,stock_quantity,is_for_sale,product_type,commission_group,upc,ean,mpn,isbn,model_number,parent_product_id,language,last_updated,dimensions,colour,keywords,custom_1,custom_2,custom_3,custom_4,custom_5,saving,delivery_weight,delivery_restrictions,reviews,average_rating,number_stars,number_available,rating,alternate_image,large_image,basket_link/format/xml/dtd/1.4/compression/gzip/adultcontent/1/');// or any url you can pass which gives you the xml filecurl_setopt($ch, CURLOPT_TIMEOUT, 50);curl_setopt($ch, CURLOPT_FILE, $fp);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);curl_exec($ch);curl_close($ch);fclose($fp);?>

 

post-186688-0-18969500-1441123314_thumb.jpg

Link to comment
Share on other sites

You don't seem to be calling fwrite() to write to the file.

 

You should set the RETURNTRANSFER curl option so you can store the result of the curl request in a variable and process it.

 

You're getting gibberish because the file you requested is GZIP compressed. You need to uncompress it first.

Link to comment
Share on other sites

You don't seem to be calling fwrite() to write to the file.

 

You should set the RETURNTRANSFER curl option so you can store the result of the curl request in a variable and process it.

 

You're getting gibberish because the file you requested is GZIP compressed. You need to uncompress it first.

It's coming direct from the people who are sending it so I'm not able to get an uncompressed version, the only options I have are ZIP or GZIP. Am I able to uncompress it using php then write the results to the server?

 

I tried adding this to the code but it still comes out as gibberish:

 

curl_setopt($ch, CURLOPT_ENCODING, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Edited by sonicthehedgehog
Link to comment
Share on other sites

Request the data the way you're doing it, store the returned data in a variable.

$data = curl_exec($ch);

You'll need to store the data temporarily in a file, you can use file_put_contents() for that.

Then use ZipArchive to load the file.

 

Read the manual, study the examples.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...