コード例 #1
0
 function log_file($s, $config)
 {
     if ($s) {
         if (!$config) {
             $config = config_get();
         }
         if (!(config_error($config) || empty($config['log_file']))) {
             if (file_safe($config['log_file'], $config)) {
                 $prelog = date('H:i:s') . ' ';
                 $prelog .= basename($_SERVER['SCRIPT_NAME']);
                 $existed = file_exists($config['log_file']);
                 $fp = fopen($config['log_file'], 'a');
                 if ($fp) {
                     $s = $prelog . ' ' . $s . "\n";
                     fwrite($fp, $s, strlen($s));
                     fclose($fp);
                 }
                 if (!$existed) {
                     file_mode($config['log_file'], $config, TRUE);
                 }
             }
         }
     }
 }
コード例 #2
0
        $file_megs = round($file_size / (1024 * 1024));
        if ($file_megs > $max) {
            $err = $type . ' files must be less than ' . $max . ' meg';
        }
    }
}
if (!$err) {
    // try to move upload into its media directory and change permissions
    $path = path_concat(path_concat(path_concat(path_concat($config['web_root_directory'], $config['user_media_directory']), $uid), $id), $config['import_original_basename'] . '.' . $file_extension);
    if (!file_safe($path, $config)) {
        $err = 'Problem creating media directory';
    } else {
        if (!file_move_upload($file['tmp_name'], $path)) {
            $err = 'Problem moving file';
        } else {
            if (!file_mode($path, $config)) {
                $err = 'Problem setting permissions of media: ' . $path;
            } else {
                log_file('Saved to: ' . $path, $config);
            }
        }
    }
    $response['status'] = 'uploaded ok';
}
if ($err) {
    $response['error'] = $err;
} else {
    $response['ok'] = 1;
}
$json = json_encode($response);
print $json . "\n\n";
コード例 #3
0
 function file_safe($path, $config = array())
 {
     $result = FALSE;
     if ($path) {
         if (!$config) {
             $config = config_get();
         }
         if (!config_error($config)) {
             $ext = file_extension($path);
             // will be empty if path is directory
             $dirs = explode('/', $path);
             if ($ext) {
                 array_pop($dirs);
             }
             // get rid of file name if path is file
             $to_create = array();
             $dir = join('/', $dirs);
             while ($dirs && !file_exists($dir)) {
                 $to_create[] = array_pop($dirs);
                 $dir = join('/', $dirs);
             }
             $z = sizeof($to_create);
             if ($z) {
                 for ($i = $z - 1; $i > -1; $i--) {
                     $dir .= '/' . $to_create[$i];
                     $result = @mkdir($dir, octdec($config['chmod_directory_new']), TRUE);
                     if ($result) {
                         $result = file_mode($dir, $config, TRUE);
                     }
                     if (!$result) {
                         break;
                     }
                 }
             } else {
                 $result = file_mode($dir, $config);
             }
         }
     }
     return $result;
 }