コード例 #1
0
ファイル: DirBox.php プロジェクト: bsa-git/zf-myblog
 /** Checks if the given directory is really writable. The standard PHP
  * function is_writable() does not work properly on Windows servers
  * @param string $dir
  * @return bool */
 static function isWritable($dir)
 {
     $dir = Default_Plugin_PathBox::normalize($dir);
     if (!is_dir($dir)) {
         return false;
     }
     $i = 0;
     do {
         $file = "{$dir}/is_writable_" . md5($i++);
     } while (file_exists($file));
     if (!@touch($file)) {
         return false;
     }
     unlink($file);
     return true;
 }
コード例 #2
0
ファイル: SysBox.php プロジェクト: bsa-git/zf-myblog
 /**
  * Copy user directory for uploading files
  * 
  * @param string $username 
  * @return bool 
  */
 static function copyUsersUploadDir()
 {
     $config = Zend_Registry::get('config');
     $patchSource = $config['paths']['backup']['dir'] . '/upload';
     $patchSource = Default_Plugin_PathBox::normalize($patchSource);
     $patchDest = APPLICATION_PUBLIC . '/upload';
     $patchDest = Default_Plugin_PathBox::normalize($patchDest);
     //-------------------------
     if (!is_dir($patchDest)) {
         if (!mkdir($patchDest)) {
             throw new Exception("Failed to create folders...'{$patchDest}'.");
         }
         if (is_dir($patchSource)) {
             // Get the FileTree object
             $ft = new Default_Plugin_FileTree($patchSource);
             // Create tree of files
             $ft->readTree();
             // Copy the current fileset to another location
             if ($ft->writeTo($patchDest) === FALSE) {
                 throw new Exception("Could not be copied '{$patchSource}' to '{$patchDest}'.");
             } else {
                 $ft->delFiles();
                 // Delete this source
             }
         } else {
             throw new Exception("There is no this dir '{$patchSource}'.");
         }
     }
 }
コード例 #3
0
ファイル: FileBox.php プロジェクト: bsa-git/zf-myblog
 /** Get inexistant filename based on the given filename. If you skip $dir
  * parameter the directory will be fetched from $filename and returned
  * value will be full filename path. The third parameter is optional and
  * defines the template, the filename will be renamed to. Default template
  * is {name}({sufix}){ext}. Examples:
  *
  *   file::getInexistantFilename("/my/directory/myfile.txt");
  *   If myfile.txt does not exist - returns the same path to the file
  *   otherwise returns "/my/directory/myfile(1).txt"
  *
  *   file::getInexistantFilename("myfile.txt", "/my/directory");
  *   returns "myfile.txt" or "myfile(1).txt" or "myfile(2).txt" etc...
  *
  *   file::getInexistantFilename("myfile.txt", "/dir", "{name}[{sufix}]{ext}");
  *   returns "myfile.txt" or "myfile[1].txt" or "myfile[2].txt" etc...
  *
  * @param string $filename
  * @param string $dir
  * @param string $tpl
  * @return string */
 static function getInexistantFilename($filename, $dir = null, $tpl = null)
 {
     if ($tpl === null) {
         $tpl = "{name}({sufix}){ext}";
     }
     $fullPath = $dir === null;
     if ($fullPath) {
         $dir = Default_Plugin_PathBox::normalize(dirname($filename));
     } else {
         $fdir = dirname($filename);
         $dir = strlen($fdir) ? Default_Plugin_PathBox::normalize("{$dir}/{$fdir}") : Default_Plugin_PathBox::normalize($dir);
     }
     $filename = basename($filename);
     $ext = self::getExtension($filename, false);
     $name = strlen($ext) ? substr($filename, 0, -strlen($ext) - 1) : $filename;
     $tpl = str_replace('{name}', $name, $tpl);
     $tpl = str_replace('{ext}', strlen($ext) ? ".{$ext}" : "", $tpl);
     $i = 1;
     $file = "{$dir}/{$filename}";
     while (file_exists($file)) {
         $file = "{$dir}/" . str_replace('{sufix}', $i++, $tpl);
     }
     return $fullPath ? $file : (strlen($fdir) ? "{$fdir}/" . basename($file) : basename($file));
 }