32 require_once
"File/Archive/Writer.php";
50 if ($base === null || $base ==
'') {
53 if (substr($base, -1) ==
'/') {
54 $this->basePath = $base;
56 $this->basePath = $base.
'/';
61 function getFilename($filename)
63 return $this->basePath.$filename;
73 if (is_dir($pathname) || empty($pathname)) {
78 if (is_file($pathname)) {
79 return PEAR::raiseError(
80 "File $pathname exists, unable to create directory"
85 $next_pathname = substr(
87 0, strrpos($pathname,
"/"));
88 $error = $this->
mkdirr($next_pathname);
89 if (PEAR::isError($error)) {
92 if (!@mkdir($pathname)) {
93 return PEAR::raiseError(
"Unable to create directory $pathname");
108 $this->handle = fopen($filename,
'r+');
109 $this->stat = array();
110 $this->filename = $filename;
112 if (!is_resource($this->handle)) {
113 return PEAR::raiseError(
"Unable to open file $filename");
117 if (fseek($this->handle, $pos) == -1) {
118 fread($this->handle, $pos);
129 $error = $this->
openFile($filename, $pos);
130 if (PEAR::isError($error)) {
134 if (!empty($blocks)) {
137 $read = fopen($filename,
'r');
139 if (fseek($this->handle, $pos) == -1) {
140 fread($this->handle, $pos);
146 foreach ($blocks as $length) {
148 while ($length > 0 &&
149 ($data = fread($read, min($length, 8192))) !=
'') {
150 $length -= strlen($data);
151 fwrite($this->handle, $data);
154 fseek($read, $length, SEEK_CUR);
159 while(!feof($this->handle)) {
160 fwrite($this->handle, fread($read, 8196));
167 ftruncate($this->handle, ftell($this->handle));
174 function newFile($filename, $stat = array(), $mime =
"application/octet-stream")
178 $this->filename = $this->getFilename($filename);
180 $pos = strrpos($this->filename,
"/");
181 if ($pos !==
false) {
182 $error = $this->
mkdirr(substr($this->filename, 0, $pos));
183 if (PEAR::isError($error)) {
187 $this->handle = @fopen($this->filename,
"w");
188 if (!is_resource($this->handle)) {
189 return PEAR::raiseError(
"Unable to write to file $filename");
195 function writeData($data) { fwrite($this->handle, $data); }
199 function newFromTempFile($tmpfile, $filename, $stat = array(), $mime =
"application/octet-stream")
201 $this->filename = filename;
202 $complete = $this->getFilename($filename);
203 $pos = strrpos($complete,
"/");
204 if ($pos !==
false) {
205 $error = $this->
mkdirr(substr($complete, 0, $pos));
206 if (PEAR::isError($error)) {
211 if ((file_exists($complete) && !@unlink($complete)) ||
212 !@rename($tmpfile, $complete)) {
213 return parent::newFromTempFile($tmpfile, $filename, $stat, $mime);
223 if ($this->handle !== null) {
224 fclose($this->handle);
225 $this->handle = null;
227 if (isset($this->stat[9])) {
228 if (isset($this->stat[8])) {
229 touch($this->filename, $this->stat[9], $this->stat[8]);
231 touch($this->filename, $this->stat[9]);
233 }
else if (isset($this->stat[8])) {
234 touch($this->filename, time(), $this->stat[8]);
237 if (isset($this->stat[2])) {
238 chmod($this->filename, $this->stat[2]);
240 # if (isset($this->stat[5])) {
241 # chgrp($this->filename, $this->stat[5]);
243 # if (isset($this->stat[4])) {
244 # chown($this->filename, $this->stat[4]);