Example #1
0
 function FileReader($file = NULL)
 {
     $fileobj = NULL;
     if (!isset($file)) {
         return;
     }
     if (URL::validClass($file)) {
         $fileobj = $file;
         $path = $fileobj->toString();
     } else {
         if (File::validClass($file)) {
             $fileobj = $file;
             $path = $fileobj->getFilePath();
         } else {
             $str = StringBuffer::toStringBuffer($file);
             if ($str->startsWith('http://') || $str->startsWith('ftp://') || $str->startsWith('php://')) {
                 $fileobj = new URL($str);
                 $path = $fileobj->toString();
             } else {
                 $fileobj = new File($file);
                 $path = $fileobj->getFilePath();
             }
         }
     }
     if (isset($fileobj)) {
         $this->handle = @fopen($path, 'r');
         if (isset($this->handle)) {
             $this->file = $fileobj;
         }
     }
 }
Example #2
0
 function accept($fileobj, $dirname)
 {
     if (File::validClass($fileobj) && (StringBuffer::validClass($dirname) || is_string($dirname))) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
Example #3
0
 function ServletContext($web_xml_file)
 {
     $web_xml_file = new File($web_xml_file);
     if (File::validClass($web_xml_file) && $web_xml_file->exists()) {
         $this->file =& $web_xml_file;
         $cache_file = new File($web_xml_file->getFilePath() . 'cached');
         $valid_cache = FALSE;
         if ($cache_file->exists() && $web_xml_file->lastModified() == $cache_file->lastModified()) {
             $this->config = @unserialize(FileReader::readFileContent($cache_file));
             if (ServletContext::validClass($this->config)) {
                 $valid_cache = TRUE;
             }
         }
         if (!$valid_cache) {
             $this->config =& ServletXMLConfigReader::readXMLConfig(new FileReader($web_xml_file));
             FileWriter::writeToFile($cache_file, serialize($this->config), $web_xml_file->lastModified());
         }
     }
     if (isset($this->config)) {
         $this->initServletContext();
     }
 }
Example #4
0
 function moveTo($file, $only_if_inexist = FALSE)
 {
     if (File::validClass($file) && $this->exists()) {
         if ($only_if_inexist == TRUE) {
             if ($file->exists() == FALSE) {
                 return rename($this->getFilePath(), $file->getFilePath());
             }
         } else {
             return rename($this->getFilePath(), $file->getFilePath());
         }
     }
     return FALSE;
 }
Example #5
0
 function loadFromStream($filename)
 {
     $buffers = new StringBuffer();
     $file = NULL;
     if (File::validClass($filename)) {
         $file = $filename;
     } else {
         $file = new File($filename);
     }
     $filereader = new FileReader($file);
     while ($c = $filereader->read()) {
         $buffers->append($c);
     }
     $this->str = $buffers->toString();
 }
Example #6
0
 /**
  * move the upload file to another location of the given parameter name
  * @param string|core.StringBuffer  parameter name
  * @param string|core.StringBuffer|core.File  parameter name
  * @return core.StringBuffer  the uploaded file name
  * @see jphp.http.interface.IHttpRequest#moveUploadedFileTo
  */
 function moveUploadedFileTo($key, $path)
 {
     $file = NULL;
     $basefile = $this->files->get($key);
     if (isset($basefile)) {
         if (File::validClass($path) || StringBuffer::validClass($path) || is_string($path)) {
             $targetfile = new File($path);
             return $basefile->moveTo($targetfile);
         }
     }
     return FALSE;
 }