CHMOD of untared (via php-script) files on webspace

by 4 replies
5
Does someone know how to modify the following function so it is possible to set the CHMOD for the extracted files? Actually I can set the folder permissions but do not know how to change the file permissions - actually all untared files have 0777 which is really bad,
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.
#programming #chmod #files #phpscript #untared #webspace
  • Are you passsing '0644' in the third variable when you call the function?
    • [1] reply
    • I just got a solution for this:

      Insteady of:

      chmod($FileName,$FileCHMOD);

      we now use:

      chmod($FileName,0755);
      • [2] replies

Next Topics on Trending Feed

  • 5

    Does someone know how to modify the following function so it is possible to set the CHMOD for the extracted files? Actually I can set the folder permissions but do not know how to change the file permissions - actually all untared files have 0777 which is really bad, I would like to set them to 0644