You are here:  » Auto Gunzip?


Auto Gunzip?

Submitted by philstone on Wed, 2006-04-26 08:47 in

hi dave

is there anyway to change

<?php
  
print "form method='post'";
  print 
"URL:";
  print 
"input type='text' name='url' size='65' /";
  print 
"Target Filename: (e.g. merchant.xml)";
  print 
"<input type='text' name='filename' /";
  print 
"<input type='submit' value='Fetch' /";
  print 
"form";
 
?>

on the fetch script so that instead of posting it can automatically have the url:
http://pf.tradedoubler.com/unlimited/unlimited_pf_FeedID_AffiliateID.xml.gz

filename AffiliateID.xml

and doesn't require the fetch button to be clicked by human?

Submitted by support on Wed, 2006-04-26 09:30

Hi Phil,

Do you mean so that the URL can be passed as a parameter, or just to hard code the URL and filename in the script?

To hard code the values, simply do this at the top of the script:

<?php
  $_POST
["url"] = "url";
  
$_POST["filename"] = "filename";
?>

If you want to be able to supply the URL and filename on the command line, you could do that like this:

<?php
  $argc 
$_SERVER["argc"];
  
$argv $_SERVER["argv"];
  if (
$argc == 3)
  {
    
$_POST["url"] = $argv[1];
    
$_POST["filename"] = $argv[2];
  }
?>

The usage would be:

$./fetch.php <url> <filename>

Always use quotes when supplying URLs and things as a command line parameter, otherwise the shell may corrupt the values. Taking your example feed; you might use:

$./fetch.php "http://pf.tradedoubler.com/unlimited/unlimited_pf_FeedID_AffiliateID.xml.gz" "merchant.xml"

Submitted by philstone on Wed, 2006-04-26 11:05

hi dave

tried that

keep getting the "wget program () not found - using PHP method" error

i get the same error with the standard fetch script, but it works ok?

Regards

phil

Submitted by support on Wed, 2006-04-26 11:06

Does that stop it working at all; or is it working using the PHP method?

Submitted by philstone on Wed, 2006-04-26 13:27

Using the old script it works first class, but nothing is imported or gunzipped now?

Submitted by support on Wed, 2006-04-26 13:33

How are you invoking the new script?

There must be a difference in the environment between executing it via web browser, and from the command line. This would explain why wget and the unzip programs cannot be found.

Do the programs work if you just type the commands at the command line? For example:

wget
unzip
gzip

(they should just display their help info)

The other thing to do will be to confirm that the section of code that does the downloading / unzipping is actually being reached. About halfway down the script you'll see the following lines:

if ($_POST["url"] && $_POST["filename"])
{
  .. rest of code ..

Add some debug code here so you can see what's going on:

if ($_POST["url"] && $_POST["filename"])
{
  print "Fetching [".$_POST["url"]."] to [".$_POST["filename"]."]\n";
  .. rest of code ..