note 104494 added to function.fopen

From: Date: Fri, 17 Jun 2011 21:57:13 +0000
Subject: note 104494 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-180652@lists.php.net to get a copy of this message
Fixed 2 issues: - Support for long filenames $FileName="././@LonkLink" - Fixed the untar of files with $FileSize=0 <?php // PHP iUnTAR Version 3.0 // license: Revised BSD license function untar($tarfile,$outdir="./",$chmod=null) { $TarSize = filesize($tarfile); $TarSizeEnd = $TarSize - 1024; if($outdir!=""&&!file_exists($outdir)) { mkdir($outdir,0777); } $thandle = fopen($tarfile, "r"); while (ftell($thandle)<$TarSizeEnd) { $FileName = $outdir.trim(fread($thandle,100)); $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); // LongLink support added by Josep Sanz if($FileName=="././@LongLink" || $FileType=="L") { $FileName = $outdir.trim(fread($thandle,$FileSize)); fseek($thandle,512-$FileSize,SEEK_CUR); fseek($thandle,100,SEEK_CUR); $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") { // Empty files support added by Josep Sanz if($FileSize==0) $FileContent = ""; else $FileContent = fread($thandle,$FileSize); } if($FileType=="1") { $FileContent = null; } if($FileType=="2") { $FileContent = null; } if($FileType=="5") { $FileContent = null; } if($FileType=="0") { $subhandle = fopen($FileName, "a+"); fwrite($subhandle,$FileContent,$FileSize); fclose($subhandle); chmod($FileName,$FileCHMOD); } if($FileType=="1") { link($FileName,$LinkedFile); } if($FileType=="2") { symlink($LinkedFile,$FileName); } if($FileType=="5") { mkdir($FileName,$FileCHMOD); } //touch($FileName,$LastEdit); if($FileType=="0") { // Empty files support added by Josep Sanz if($FileSize>0) { $CheckSize = 512; while ($CheckSize<$FileSize) { if($CheckSize<$FileSize) { $CheckSize = $CheckSize + 512; } } $SeekSize = $CheckSize - $FileSize; fseek($thandle,$SeekSize,SEEK_CUR); } } } fclose($thandle); return true; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 88.15.82.143 ---- Manual Page -- http://www.php.net/manual/en/function.fopen.php Edit -- https://master.php.net/note/edit/104494 Del: integrated -- https://master.php.net/note/delete/104494/integrated Del: useless -- https://master.php.net/note/delete/104494/useless Del: bad code -- https://master.php.net/note/delete/104494/bad+code Del: spam -- https://master.php.net/note/delete/104494/spam Del: non-english -- https://master.php.net/note/delete/104494/non-english Del: in docs -- https://master.php.net/note/delete/104494/in+docs Del: other reasons-- https://master.php.net/note/delete/104494 Reject -- https://master.php.net/note/reject/104494 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180652) next »