CHMOD of untared (via php-script) files on webspace
I would like to set them to 0644
Here comes the function:
function untar($tarfile, $outdir="./", $chmod = null) {
global $log, $LANG, $lang;
$TarSize = filesize($tarfile);
$TarSizeEnd = $TarSize - 1024;
if($outdir!="" && !file_exists($outdir)) {
@mkdir($outdir,0755,true);
}
$thandle = fopen($tarfile, "r");
while (ftell($thandle) < $TarSizeEnd) {
$FileName = fread($thandle,100);
$FileName = $outdir.trim($FileName);
$FileMode = trim(fread($thandle,8));
if($chmod===null) {
$FileCHMOD = octdec("0".substr($FileMode,-3));
}
if($chmod!==null) {
$FileCHMOD = $chmod;
}
$OwnerID = trim(fread($thandle,8));
$GroupID = trim(fread($thandle,8));
$FileSize = octdec(trim(fread($thandle,12)));
$LastEdit = trim(fread($thandle,12));
$Checksum = trim(fread($thandle,8));
$FileType = trim(fread($thandle,1));
$LinkedFile = trim(fread($thandle,100));
fseek($thandle,255,SEEK_CUR);
if($FileType=="0") {
if ($FileSize>0) {
$FileContent = fread($thandle,$FileSize);
} else {
$FileContent = '';
}
}
if($FileType=="1") {
$FileContent = null;
}
if($FileType=="2") {
$FileContent = null;
}
if($FileType=="5") {
$FileContent = null;
}
if($FileType=="0") {
if (!file_exists(dirname($FileName))) {
@mkdir(dirname($FileName), 0755, true);
}
$subhandle = fopen($FileName, "w");
$log .= $LANG[$lang]['L_FILE'].$FileName."\n";
fwrite($subhandle,$FileContent,$FileSize);
fclose($subhandle);
chmod($FileName,$FileCHMOD);
}
if($FileType=="1") {
//link($FileName,$LinkedFile);
$log .= $FileName." link!\n";
}
if($FileType=="2") {
//symlink($LinkedFile,$FileName);
$log .= $FileName." symlink!\n";
}
if($FileType=="5") {
$log .= $LANG[$lang]['L_DIR'].$FileName."\n";
@mkdir($FileName, 0755, true);
}
//touch($FileName,$LastEdit);
if($FileType=="0") {
$CheckSize = $FileSize == 0 ? 0 : 512;
while ($CheckSize<$FileSize) {
if($CheckSize<$FileSize) {
$CheckSize = $CheckSize + 512;
}
}
$SeekSize = $CheckSize - $FileSize;
fseek($thandle,$SeekSize,SEEK_CUR);
}
}
fclose($thandle);
return true;
}
Any help is very much appreciated.
Feel free to contact me directly and I will give you the details!