Ejemplo n.º 1
0
 public static function move($sourcePath, $destPath)
 {
     // Reject the directory if it has illegal characters
     if (!IsSanitized::filepath($sourcePath) or !IsSanitized::filepath($destPath)) {
         return false;
     }
     // Create the base destination path
     self::create($destPath);
     // Get all files (including recursively) in the folder
     $files = self::getFiles($sourcePath, true, true);
     $success = true;
     // Copy all of the files
     foreach ($files as $file) {
         if (is_dir($sourcePath . "/" . $file)) {
             if (!self::create($destPath . '/' . $file)) {
                 $success = false;
             }
             continue;
         }
         if (!copy($sourcePath . '/' . $file, $destPath . '/' . $file)) {
             $success = false;
         }
     }
     // Delete the source folder if the move was successful
     return $success ? self::delete($sourcePath) : false;
 }
Ejemplo n.º 2
0
 public static function exists($filepath)
 {
     // If the filepath is using illegal characters or entries, reject the function
     if (!IsSanitized::filepath($filepath)) {
         return false;
     }
     return is_file($filepath);
 }
Ejemplo n.º 3
0
 public static function package($source, $targetFile, $incParent = false)
 {
     // Make sure we're able to use the zip library
     if (!extension_loaded('zip')) {
         return false;
     }
     // Prepare the path
     $source = str_replace('\\', '/', realpath($source));
     // Make sure the file exists and is safe
     if (!IsSanitized::filepath($source)) {
         return false;
     }
     if (!file_exists($source)) {
         return false;
     }
     // Make sure the directory exists
     $targetDir = dirname($targetFile);
     if (!is_dir($targetDir)) {
         Dir::create($targetDir);
     }
     // Prepare the Zip Functionality
     $zip = new ZipArchive();
     if (!$zip->open($targetFile, ZIPARCHIVE::CREATE)) {
         return false;
     }
     // Run the Zip Processer
     if (is_dir($source) === true) {
         $baseDir = '';
         if ($incParent) {
             $exp = explode("/", $source);
             $baseDir = $exp[count($exp) - 1] . '/';
             $zip->addEmptyDir($baseDir);
         }
         $files = Dir::getFiles($source, true, true);
         foreach ($files as $file) {
             if (is_dir($source . '/' . $file) === true) {
                 $zip->addEmptyDir($baseDir . $file);
             } else {
                 if (is_file($source . '/' . $file) === true) {
                     $zip->addFile($source . '/' . $file, $baseDir . $file);
                 }
             }
         }
     } else {
         if (is_file($source) === true) {
             $zip->addFile($file);
         }
     }
     return $zip->close();
 }
Ejemplo n.º 4
0
 public function save($file, $quality = 90)
 {
     // Allow Transparency
     imagesavealpha($this->resource, true);
     // If the save file is valid
     if (!IsSanitized::filepath($file)) {
         Alert::error("Image Path", "The image path is invalid.", 7);
         return false;
     }
     $saveInfo = pathinfo($file);
     if (!isset($saveInfo['basename']) or !isset($saveInfo['dirname']) or !isset($saveInfo['extension'])) {
         Alert::error("Image Path", "The image path is not functioning properly.", 6);
         return false;
     }
     // Make sure the directory exists
     if (!Dir::create($saveInfo['dirname'])) {
         Alert::error("Image Directory", "The image directory cannot be created. Please check permissions.", 4);
         return false;
     }
     // Save the file
     switch ($saveInfo['extension']) {
         case "jpg":
         case "jpeg":
             return imagejpeg($this->resource, $file, $quality);
         case "png":
             return imagepng($this->resource, $file);
         case "gif":
             return imagegif($this->resource, $file);
     }
     return false;
 }
Ejemplo n.º 5
0
 public function validatePath($savePath = "")
 {
     if ($this->valid == false) {
         return false;
     }
     // If the save path is valid
     $saveInfo = pathinfo($savePath);
     if (!isset($saveInfo['basename']) or !isset($saveInfo['dirname']) or !isset($saveInfo['extension'])) {
         $this->valid = false;
         return false;
     }
     // Set values
     $this->saveDirectory = $saveInfo['dirname'];
     $this->filename = $saveInfo['filename'];
     $this->toExtension = $saveInfo['extension'];
     // Make sure the characters are valid
     $this->saveDirectory = rtrim(str_replace("\\", "/", $this->saveDirectory), "/");
     if (!IsSanitized::filepath($this->saveDirectory . '/' . $this->filename . '.' . $this->extension)) {
         Alert::error("Upload Filename", "The save destination is invalid - illegal extension or characters.", 9);
         $this->valid = false;
         return false;
     }
     // Confirm that the directory exists (otherwise create it)
     if (!Dir::create($this->saveDirectory)) {
         Alert::error("Upload Directory", "The upload directory cannot be created. Please check permissions.", 4);
         $this->valid = false;
         return false;
     }
     return true;
 }