I am running it using this script. It downloaded a file from a http address when I did a test. For some reason it can't seem to execute the import.php file.
Here is the script(I am using the code posted on this forum):
---------------------------------------------------------------------------------
<?php
set_time_limit(0);
ignore_user_abort();
// destination directory for downloaded files - must be writable by PHP
$targetDir = "../feeds/";
// path to wget program for retrieval
$wgetProgram = "/usr/bin/wget";
// path to various unzip programs
$unzipPrograms["zip"] = "/usr/bin/unzip";
//$unzipPrograms["rar"] = "/usr/bin/unrar";
//$unzipPrograms["gzip"] = "/usr/bin/gzip";
// check that target directory is writable, bail otherwise
if (!is_writable($targetDir))
{
print "<p>target directory ($targetDir) not writable - exiting</p>";
exit();
}
// check that wget binary exists, bail otherwise
if (!file_exists($wgetProgram))
{
print "<p>wget program ($wgetProgram) not found - using PHP method</p>";
$usePHP = true;
}
// check for and disable any unzip methods that do not exist
foreach($unzipPrograms as $name => $program)
{
if (!file_exists($program))
{
print '<p>unzip program for '.$name.' ('.$program.') not found - disabled</p>';
unset($unzipPrograms[$name]);
}
}
function fetch_url($url,$filename)
{
$source = fopen($url,"r");
$destination = fopen($filename,"w");
if (!$source || !$destination) return;
while(!feof($source))
{
fwrite($destination,fread($source,2048));
}
fclose($source);
fclose($destination);
}
function unzip_zip($header,$filename)
{
global $unzipPrograms;
// check if zip format
if ($header <> "PK".chr(0x03).chr(0x04)) return false;
$command = $unzipPrograms["zip"]." -p ".$filename." > ".$filename.".unzipped";
exec($command);
unlink($filename);
rename($filename.".unzipped",$filename);
return true;
}
function unzip_rar($header,$filename)
{
global $unzipPrograms;
// check if rar format
if ($header <> "Rar!") return false;
$command = $unzipPrograms["rar"]." p -inul ".$filename." > ".$filename.".unrarred";
exec($command);
unlink($filename);
rename($filename.".unrarred",$filename);
return true;
}
function unzip_gzip($header,$filename)
{
global $unzipPrograms;
// gzip only way to tell is to try
$command = $unzipPrograms["gzip"]." -c -d -S \"\" ".$filename." > ".$filename.".ungzipped";
exec($command);
if (filesize($filename.".ungzipped"))
{
unlink($filename);
rename($filename.".ungzipped",$filename);
return true;
}
else
{
unlink($filename.".ungzipped");
return false;
}
}
function fetch($url,$filename)
{
global $usePHP;
global $targetDir;
global $wgetProgram;
global $unzipPrograms;
$temporaryFilename = $targetDir.uniqid("");
// fetch the file
if ($usePHP)
{
fetch_url($url,$temporaryFilename);
}
else
{
$command = $wgetProgram." --ignore-length -O ".$temporaryFilename." \"".$url."\"";
exec($command);
}
// bail if download has failed
if (!file_exists($temporaryFilename))
{
print "<p>download failed - exiting</p>";
exit();
}
// read the first 4 bytes to pass to unzip functions
$filePointer = fopen($temporaryFilename,"r");
$fileHeader = fread($filePointer,4);
fclose($filePointer);
// try and unzip the file by calling each unzip function
foreach($unzipPrograms as $name => $program)
{
$unzip_function = "unzip_".$name;
if ($unzip_function($fileHeader,$temporaryFilename)) break;
}
// finally rename to required target (delete existing if necessary)
$targetFilename = $targetDir.$filename;
if (file_exists($targetFilename))
{
unlink($targetFilename);
}
rename($temporaryFilename,$targetFilename);
// all done!
}
fetch("http://www.MYDOWNLOADSITE.com/file.txt","file.txt");
//fetch("ftp://username:password@www.example.org/merchant/123.txt","123.txt");
exec("php /kunden/homepages/FULL-PATH/import.php");
//phpinfo();
?>
Any help is much appreciated.
I tried that and that does not seem to help. What else can I do?
Hi,
The next steps to solve this is first to make sure that the import process is working for this specific feed.
- Firstly, does the feed import successfully via the admin interface?
If the feed does not import, the most common reason is a registration error (where the wrong field has been registered) resulting in one of the manadatory fields (product name, buy URL or price) being blank for every record.
- If the feed does import via the admin interface, what happens when you try and run import.php from the command line, outside of your automation script?
To do this you will need to be able to login to your server via Telnet or SSH. After logging in, navigate to the scripts directory and run the command as follows:
php import.php file.txt
This way, you will be able to see any error message that is being generated by import.php which may help.
Cheers,
David.
Hi,
import.php requires a parameter, either a filename or @MODIFIELD or @ALL, and I notice that there is no parameter provided in the code above. The following line in your script:
exec("php /kunden/homepages/FULL-PATH/import.php");
...should be:
exec("php /kunden/homepages/FULL-PATH/import.php @MODIFIED");
Alternatively, you could make it:
exec("php /kunden/homepages/FULL-PATH/import.php file.txt");
...which would just import file.txt regardless of the modification date; but in most circumstances @MODIFIED would be used. @ALL will import all feeds.
Hope this helps,
David.