Example #1
0
 function testBlackHole()
 {
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/black_hole_test.php");
     $this->assertTrue($f->exists(), "Il file del test non esiste!!");
     $content = $f->getContent();
     $f->delete();
     $this->assertFalse($f->exists(), "Il file del test black hole non e' stato eliminato!!");
     $f->touch();
     $f->setContent($content);
     $this->assertTrue($f->exists(), "Il file del test black hole non e' stato rigenerato!!");
 }
Example #2
0
	/**
	 * Extracts a specific file and writes it's content
	 * to the file specified with $destination.
	 *
	 * @param	mixed		$index		index or name of the requested file
	 * @param	string		$destination
	 * @return	boolean	$success
	 */
	public function extract($index, $destination) {
		if (!$this->read) {
			$this->open();
			$this->readContent();
		}
		$header = $this->getFileInfo($index);
		
		// can not extract a folder
		if ($header['type'] != 'file') {
			return false;
		}
		
		// seek to offset
		$this->file->seek($header['offset']);
		
		$targetFile = new File($destination);
		
		// read data
		$n = floor($header['size'] / 512);
		for ($i = 0; $i < $n; $i++) {
			$content = $this->file->read(512);
			$targetFile->write($content, 512);
		}
		if (($header['size'] % 512) != 0) {
			$content = $this->file->read(512);
			$targetFile->write($content, ($header['size'] % 512));
		}
		
		$targetFile->close();
		if (function_exists('apache_get_version') || !@$targetFile->is_writable()) {
			@$targetFile->chmod(0777);
		}
		else {
			@$targetFile->chmod(0755);
		}
		
		if ($header['mtime']) {
			@$targetFile->touch($header['mtime']);
		}
		
		// check filesize
		if (filesize($destination) != $header['size']) {
			throw new SystemException("Could not untar file '".$header['filename']."' to '".$destination."'. Maybe disk quota exceeded in folder '".dirname($destination)."'.");
		}
		
		return true;
	}
Example #3
0
 function perform()
 {
     // fetch the data needed from the request
     $this->_dbServer = $this->_request->getValue("dbServer");
     $this->_dbUser = $this->_request->getValue("dbUser");
     $this->_dbPassword = $this->_request->getValue("dbPassword");
     $this->_dbName = $this->_request->getValue("dbName");
     $this->_skipThis = $this->_request->getValue("skipDbInfo");
     $this->_dbPrefix = $this->_request->getValue("dbPrefix", DEFAULT_DB_PREFIX);
     // we should now save the data to the configuration file, just before
     // we read it
     $configFile = new ConfigFileStorage();
     // we expect everything to be fine
     $errors = false;
     // before doing anything, we should check of the configuration file is
     // writable by this script, or else, throw an error and bail out gracefully
     $configFileName = $configFile->getConfigFileName();
     if (!File::exists($configFileName)) {
         if (!File::touch($configFileName)) {
             $this->_view = new WizardView("intro");
             $message = "Could not create the pLog configuration file {$configFileName}. Please make sure\n                                that the file can be created by the user running the webserver. It is needed to\n                                store the database configuration settings.";
             $this->_view->setErrorMessage($message);
             $this->setCommonData(true);
             return false;
         } else {
             ConfigFileStorage::createConfigFile($configFileName);
         }
     }
     if (File::exists($configFileName) && !File::isWritable($configFileName)) {
         $this->_view = new WizardView("intro");
         $message = "Please make sure that the file {$configFileName} can be written by this script during\n                            the installation process. It is needed to store the database configuration settings. Once the\n                            installation is complete, please revert the permissions to no writing possible.";
         $this->_view->setErrorMessage($message);
         $this->setCommonData(true);
         return false;
     }
     // continue if everything went fine
     if (!$configFile->saveValue("db_username", $this->_dbUser) || !$configFile->saveValue("db_password", $this->_dbPassword) || !$configFile->saveValue("db_host", $this->_dbServer) || !$configFile->saveValue("db_database", $this->_dbName) || !$configFile->saveValue("db_prefix", $this->_dbPrefix)) {
         $errors = true;
     }
     if ($errors) {
         $message = "Could not save values to the configuration file. Please make sure it is available and\n                            that has write permissions for the user under your web server is running.";
         $this->_view = new WizardView("intro");
         $this->_view->setErrorMessage($message);
         return false;
     } else {
         $this->_view = new WizardView("step1");
         // now we better read the information from the config file to make sure that
         // it has been correctly saved
         $this->setCommonData(true);
         return true;
     }
 }
Example #4
0
 /**
  * Make a thumbnail of the image. (Requires GD)
  * TODO: Make imagemagick an acceptable alternative.
  */
 public function makeThumbnail($outputFile, $maxWidth, $maxHeight)
 {
     $f = new File($outputFile);
     if ($f->exists()) {
         return;
     }
     $img = NULL;
     switch ($this->mimetype()) {
         case 'image/jpeg':
             $img = imagecreatefromjpeg($this->imagePath);
             break;
         case 'image/gif':
             $img = imagecreatefromgif($this->imagePath);
             break;
         case 'image/png':
             $img = imagecreatefrompng($this->imagePath);
             break;
         default:
             echo "Err: Cannot make thumbnail from type: \"" . $this->mimetype() . "\".";
             return;
     }
     $size = $this->size();
     $width = $size[0];
     $height = $size[1];
     // TODO: Improve resize algorithm
     $newWidth = 0;
     $newHeight = 0;
     if ($width > $height) {
         $newWidth = $maxWidth;
         $newHeight = $height / $width * $maxHeight;
         if ($newWidth < $maxHeight) {
             $newHeight = $maxHeight;
             $newWidth = $width / $height * $maxWidth;
         }
     } else {
         $newHeight = $maxHeight;
         $newWidth = $width / $height * $maxWidth;
         if ($newWidth < $maxHeight) {
             $newWidth = $maxWidth;
             $newHeight = $height / $width * $maxHeight;
         }
     }
     $new = imagecreatetruecolor($newWidth, $newHeight);
     imagecopyresampled($new, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
     // Must create file
     $o = new File($outputFile);
     $o->touch();
     // Save encoding based on extension
     $ext = substr($outputFile, -4);
     switch ($ext) {
         case '.jpg':
         case 'jpeg':
             imagejpeg($new, $outputFile);
             // TODO: Quality
             break;
         case '.png':
             imagepng($new, $outputFile);
             break;
         case '.gif':
             imagegif($new, $outputFile);
             break;
     }
     imagedestroy($new);
     imagedestroy($img);
 }
Example #5
0
File: File.php Project: rsms/phpab
 /**
  * @param  string
  * @param  string
  * @param  string
  * @return File
  */
 public static function createTempFile($prefix = '', $suffix = '', $inDir = '/tmp', $deleteOnExit = true)
 {
     if (($file = tempnam($inDir, $prefix) . $suffix) === false) {
         throw new IOException('Failed to create temporary file ' . $file);
     }
     $file = new File($file);
     @$file->touch();
     @$file->chmod(0664);
     if ($deleteOnExit) {
         $file->deleteOnExit();
     }
     return $file;
 }
Example #6
0
 function testIncludeAndDelete()
 {
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/files_to_include/include_and_delete_me.php.inc");
     $this->assertTrue($f->exists(), "Il file da includere e cancellare non esiste!!");
     $this->assertFalse(class_exists("IncludeDeletedClass"), "La classe IncludeDeletedClass esiste prima dell'inclusione del file.");
     $f->requireFileOnce();
     $this->assertTrue(class_exists("IncludeDeletedClass"), "La classe IncludeDeletedClass non e' stata caricata dopo l'inclusione del file.");
     $content = $f->getContent();
     $f->delete();
     $this->assertFalse($f->exists(), "Il file da includere e cancellare non e' stato eliminato!!");
     $f->touch();
     $f->setContent($content);
     $this->assertTrue($f->exists(), "Il file da includere e cancellare non e' stato rigenerato!!");
 }