Hi
I am trying to run a php script to obtain files and then unzip them. The program will not run as the files are in the root and I dont have permission from within the VPS. I do however have access to the php.ini in the root and the .conf files as all the sites running on the VPS belong to us.
We are trying to run the Wget and Gzip etc. I enclose part of the code. The issue i think can be solved from the php.ini or the .conf file but not sure what to edit to allow.
<?php
// 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;
}
*/
$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;
Thanks
Roy