function filesize($path) { return Mageplace_Backup_Model_File::filesize($path); }
public function getDirSize($path, $loop = 0) { $fileSize = 0; $dir = scandir($path); foreach ($dir as $file) { if ($file != '.' && $file != '..') { if (is_link($path . DS . $file)) { continue; } elseif (is_dir($path . DS . $file)) { if ($loop >= self::MAX_LOOP) { $this->_loop = true; continue; } else { $fileSize += (double) $this->getDirSize($path . DS . $file, $loop + 1); } } else { $fileSize += Mageplace_Backup_Model_File::filesize($path . DS . $file); } } } return $fileSize; }
public function prepareFileToUpload($size = self::DEFAULT_FILE_PART_SIZE) { if ($size < 0.001) { $size = 0; } $sizeByte = round($size * 1024 * 1024); if (!$sizeByte || Mageplace_Backup_Model_File::filesize($this->getFileLocation()) <= $sizeByte) { return array(array('filename' => $this->getFileName(), 'filelocation' => $this->getFileLocation())); } $this->_addBackupProcessMessage($this->_helper->__('Start splitting "%s" file into parts', $this->getFileName()), Mageplace_Backup_Model_Backup::LOG_LEVEL_INFO); $readFilePartSize = $size < self::READ_FILE_PART_SIZE ? self::READ_FILE_PART_SIZE / 1024 : self::READ_FILE_PART_SIZE; $counter = 0; $return = array(); $handle = fopen($this->getFileLocation(), 'r'); while (!feof($handle)) { $counter++; $filename = $this->getFileName(null, $counter); $fileLoc = $this->getPath() . DS . $this->getFileName(null, $counter); $sizeCounter = 0; $handle_w = fopen($fileLoc, 'a'); $this->getBackup()->addFilesForDelete($fileLoc); $wrote = true; do { $filePart = fread($handle, $readFilePartSize); if (fwrite($handle_w, $filePart) === false) { $wrote = false; break; } $sizeCounter += $readFilePartSize; } while ($sizeCounter < $sizeByte && !feof($handle)); fclose($handle_w); if ($wrote == false) { $this->_addBackupProcessMessage($this->_helper->__("Write file \"%s\" error. Split process was stopped.", $fileLoc), Mageplace_Backup_Model_Backup::LOG_LEVEL_WARNING); break; } else { $return[] = array('filename' => $filename, 'filelocation' => $fileLoc); } } fclose($handle); $this->setFileParts($counter); $this->_addBackupProcessMessage($this->_helper->__('Finish splitting "%s" file into parts', $this->getFileName()), Mageplace_Backup_Model_Backup::LOG_LEVEL_INFO); return $return; }
protected function filesize($handle) { return Mageplace_Backup_Model_File::filesize($handle); }