Example #1
0
 function writeToFile($file, $contents, $last_modified = '0')
 {
     $file = new File($file);
     $handle = @fopen($file->getFilePath(), "w");
     if (!empty($handle)) {
         fputs($handle, $contents, strlen($contents));
         fclose($handle);
         if ($last_modified > 0) {
             touch($file->getFilePath(), $last_modified);
         }
         return TRUE;
     }
     return FALSE;
 }
Example #2
0
 public function backup()
 {
     if ($this->isLocalBackupEnabled() || $this->isFTPBackupEnabled()) {
         $sourceConfig = DatabaseConfig::getInstanceFromConfigFile();
         $source = new MysqlSource($sourceConfig);
         $fileDest = new File($sourceConfig);
         $dbBackup = new DatabaseBackup($source, $fileDest);
         $dbBackup->backup();
         $this->location->limitBackup();
         $this->zip->addFile($fileDest->getFilePath(), false);
         foreach ($this->folderList as $folder) {
             $path = $this->getFolderPath($folder);
             $folder = $this->addTrailingSlash($folder);
             $this->zip->addDirectory($path, $folder);
         }
         $this->zip->close();
         $this->location->save($this->getBackupFileName());
         if (file_exists($fileDest->getFilePath())) {
             //unlink($fileDest->getFilePath());
         }
     }
 }
Example #3
0
 public function executeUploadFile(sfWebRequest $request, $type)
 {
     $this->forward404Unless($request->isMethod('POST'));
     $dest = File::getFilePath($type, $this->course->url, $this->lecture->url, $this->user->username);
     $this->forms[$type]->getValidator('file')->setOption('path', $dest);
     $this->forms[$type]->bind($request->getParameter($type), $request->getFiles($type));
     if ($this->forms[$type]->isValid()) {
         $this->forms[$type]->updateObject($this->getObjectData());
         $this->forms[$type]->save();
         $this->getUser()->setFlash('message', 'Sikeresen feltöltötted a !' . $type);
         $this->redirect($request->getUri());
     }
 }
Example #4
0
 function readFileContent($file)
 {
     $file = new File($file);
     if ($file->exists()) {
         $handle = @fopen($file->getFilePath(), "r");
         if (!empty($handle)) {
             $contents = fread($handle, filesize($file->getFilePath()));
             fclose($handle);
             return $contents;
         }
     }
     return NULL;
 }
Example #5
0
 public function testSimpleGetters()
 {
     $this->assertEquals('dir/file.css', $this->object->getFilePath());
     $this->assertSame($this->context, $this->object->getContext());
     $this->assertEquals('Magento_Module', $this->object->getModule());
 }
Example #6
0
 /**
  * function return set file to user
  *
  * @param File $oFile file object
  *
  * @param bool $dispositionInline if true then diposition is 'inline' else
  * 									disposition is 'attachment', default -
  * 									true (disposition 'inline')
  * @return bool is file sent
  */
 function downloadFile($oFile, $dispositionInline = false)
 {
     if (empty($oFile)) {
         $this->farrErrors[] = "File not set";
         return false;
     }
     if (!$oFile->getFileMimeType()) {
         $this->farrErrors[] = "File mime type not set";
         return false;
     }
     $disposition = $dispositionInline ? $disposition = 'inline' : ($disposition = 'attachment');
     header('Content-type: ' . $oFile->getFileMimeType());
     header('Content-Disposition: ' . $disposition . '; filename="' . $oFile->getFileUserName() . '"');
     header('Content-Length: ' . $oFile->getFileSize());
     readfile($oFile->getFilePath() . $oFile->getFileName());
     return true;
 }
Example #7
0
 public static function resizeImage($source_file, $dest_file, $width, $height, $crop = false)
 {
     if (!is_readable($source_file)) {
         $source_file = File::getFilePath($source_file);
     }
     if (!is_readable($dest_file)) {
         $dest_file = File::getFilePath($dest_file);
     }
     if (!file_exists($source_file)) {
         throw new Exception('Original image file not found!');
     }
     $source_extension = strtolower(File::getFileExtension($source_file));
     $dest_extension = strtolower(File::getFileExtension($dest_file));
     switch ($source_extension) {
         case 'jpg':
         case 'jpeg':
             $img = imagecreatefromjpeg($source_file);
             break;
         case 'gif':
             $img = imagecreatefromgif($source_file);
             break;
         case 'png':
             $img = imagecreatefrompng($source_file);
             break;
         default:
             throw new Exception('Image format not supported.');
             break;
     }
     list($w, $h) = getimagesize($source_file);
     if ($w === $width && $h === $height) {
         $new = $img;
         // Preserve transparency
         if ($source_extension == "gif" || $source_extension == "png") {
             imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
             imagealphablending($new, false);
             imagesavealpha($new, true);
         }
     } else {
         if ($crop) {
             $width_new = $h * $width / $height;
             $height_new = $w * $height / $width;
             //if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa
             if ($width_new > $width) {
                 $x = 0;
                 $y = ($h - $height_new) / 2;
                 $h = $height_new;
             } else {
                 $x = ($w - $width_new) / 2;
                 $y = 0;
                 $w = $width_new;
             }
         } else {
             $ratio = min($width / $w, $height / $h);
             $width = $w * $ratio;
             $height = $h * $ratio;
             $x = 0;
             $y = 0;
         }
         $new = imagecreatetruecolor($width, $height);
         // Preserve transparency
         if ($source_extension == "gif" || $source_extension == "png") {
             imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
             imagealphablending($new, false);
             imagesavealpha($new, true);
         }
         imagecopyresampled($new, $img, 0, 0, $x, $y, $width, $height, $w, $h);
     }
     switch ($dest_extension) {
         case 'jpg':
         case 'jpeg':
             imagejpeg($new, $dest_file, 90);
             break;
         case 'gif':
             imagegif($new, $dest_file);
             break;
         case 'png':
             imagepng($new, $dest_file, 5);
             break;
     }
 }