function directory_size_kb($dir)
{
    $size = 0;
    $cmd = 'du -s ' . $dir;
    $result = shell_command($cmd);
    if ($result) {
        $result = explode("\t", $result);
        $result = array_shift($result);
        if (is_numeric($result)) {
            $size += $result;
        }
    }
    return $size;
}
function get_file_info($type, $file_path, $ffmpeg = '')
{
    $result = FALSE;
    if ($file_path) {
        $info_file = meta_file_path($type, $file_path);
        $result = file_get($info_file);
        if (!$result) {
            if (file_exists($file_path)) {
                $check = array();
                switch ($type) {
                    case 'type':
                        // do nothing if file doesn't already exist
                    // do nothing if file doesn't already exist
                    case 'http':
                    case 'ffmpeg':
                        break;
                    case 'Server':
                        // HTTP header data
                    // HTTP header data
                    case 'ETag':
                    case 'Date':
                    case 'Last-Modified':
                    case 'Content-Length':
                    case 'Content-Type':
                        $check['http'] = TRUE;
                        break;
                    case 'dimensions':
                        if (get_file_type($file_path) == 'image') {
                            // we can get dimensions of images with php
                            $check['php'] = TRUE;
                            break;
                        }
                    case 'duration':
                        /* for when we can get duration of audio from php
                        			if (get_file_type($file_path) == 'audio')
                        			{
                        				$check['php'] = TRUE;
                        				break;
                        			}
                        			*/
                    /* for when we can get duration of audio from php
                    			if (get_file_type($file_path) == 'audio')
                    			{
                    				$check['php'] = TRUE;
                    				break;
                    			}
                    			*/
                    case 'fps':
                        // only from FFMPEG
                    // only from FFMPEG
                    case 'audio':
                        $check['ffmpeg'] = TRUE;
                        break;
                    default:
                        // something other than http info needed
                        switch (get_file_type($file_path)) {
                            case 'image':
                            case 'video':
                            case 'audio':
                                break;
                            default:
                                // couldn't get media type or type unrecognizable
                                $check['http'] = TRUE;
                        }
                }
                if (!empty($check['php'])) {
                    // for now just images supported
                    $data = @getimagesize($file_path);
                    if ($data && $data[0] && $data[1]) {
                        $result = $data[0] . 'x' . $data[1];
                    }
                }
                if (!empty($check['ffmpeg'])) {
                    $data = get_file_info('ffmpeg', $file_path);
                    if (!$data) {
                        if ($ffmpeg) {
                            $cmd = $ffmpeg;
                            $cmd .= ' -i ' . $file_path;
                            $data = shell_command($cmd);
                            set_file_info($file_path, 'ffmpeg', $data);
                        }
                    }
                    if ($data) {
                        $result = ffmpeg_info_from_string($type, $data);
                    }
                }
                if (!empty($check['http'])) {
                    $data = get_file_info('http', $file_path);
                    if ($data) {
                        $data = http_info_from_string($type, $data);
                        if ($data) {
                            $result = $data;
                        }
                    }
                }
                // try to cache the data for next time
                set_file_info($file_path, $type, $result);
            }
        }
    }
    return $result;
}
示例#3
0
 function _shellExecute($s, $target = ' 2>&1', $dont_encode = 0)
 {
     $v = $this->getOption('Verbose');
     if ($v) {
         $this->log($s . $target);
     }
     $output = shell_command($s, $target, $dont_encode);
     if ($v) {
         $this->log($output);
     }
     return $output;
 }