Beispiel #1
0
/**
 * Helper function for upgrade - get path from upload:// name
 * @param string $path
 * return string
 */
function getUploadRelativeName($path)
{
    if (class_exists('UploadFile')) {
        return UploadFile::realpath($path);
    }
    if (substr($path, 0, 9) == "upload://") {
        $path = rtrim($GLOBALS['sugar_config']['upload_dir'], "/\\") . "/" . substr($path, 9);
    }
    return $path;
}
 public function getProcessImage($api, $args)
 {
     $path = 'upload://tmp/';
     $image = new PMSEImageGenerator();
     $img = $image->get_image($args['record']);
     $file = new UploadStream();
     if (!$file->checkDir($path)) {
         $file->createDir($path);
     }
     $file_path = UploadFile::realpath($path) . '/' . $args['record'];
     imagepng($img, $file_path);
     imagedestroy($img);
 }
Beispiel #3
0
require_once 'modules/MailMerge/MailMerge.php';
global $beanList, $beanFiles;
$module = $_POST['mailmerge_module'];
$document_id = $_POST['document_id'];
$selObjs = urldecode($_POST['selected_objects_def']);
$item_ids = array();
parse_str($selObjs, $item_ids);
$class_name = $beanList[$module];
$includedir = $beanFiles[$class_name];
require_once $includedir;
$seed = new $class_name();
$fields = get_field_list($seed);
$document = new Document();
$document->retrieve($document_id);
$items = array();
foreach ($item_ids as $key => $value) {
    $seed->retrieve($key);
    $items[] = $seed;
}
ini_set('max_execution_time', 600);
ini_set('error_reporting', 'E_ALL');
$dataDir = create_cache_directory("MergedDocuments/");
$fileName = UploadFile::realpath("upload://{$document->document_revision_id}");
$outfile = pathinfo($document->filename, PATHINFO_FILENAME);
$mm = new MailMerge(null, null, $dataDir);
$mm->SetDataList($items);
$mm->SetFieldList($fields);
$mm->Template(array($fileName, $outfile));
$file = $mm->Execute();
$mm->CleanUp();
header("Location: index.php?module=MailMerge&action=Step4&file=" . urlencode($file));
Beispiel #4
0
/**
 * Zip list of files, optionally stripping prefix
 * FIXME: check what happens with streams
 * @param string $zip_file
 * @param array $file_list
 * @param string $prefix Regular expression for the prefix to strip
 */
function zip_files_list($zip_file, $file_list, $prefix = '')
{
    $archive = new ZipArchive();
    $res = $archive->open(UploadFile::realpath($zip_file), ZipArchive::CREATE | ZipArchive::OVERWRITE);
    // we need realpath here for PHP streams support
    if ($res !== TRUE) {
        $GLOBALS['log']->fatal("Unable to open zip file, check directory permissions: {$zip_file}");
        return FALSE;
    }
    foreach ($file_list as $file) {
        if (!empty($prefix) && preg_match($prefix, $file, $matches) > 0) {
            $zipname = substr($file, strlen($matches[0]));
        } else {
            $zipname = $file;
        }
        $archive->addFile($file, $zipname);
    }
    return TRUE;
}
Beispiel #5
0
/**
 * Attempts to use PHPs mime type getters, where available, to get the content
 * type of a file. Checks existence of the file
 *
 * @param string $file The filepath to get the mime type for
 * @param string $default An optional mimetype string to return if one cannot be found
 * @return string The string content type of the file or false if the file does
 *                not exist
 */
function get_file_mime_type($file, $default = false)
{
    // If the file is readable then use it
    if (is_readable($file)) {
        $file = UploadFile::realpath($file);
        // Default the return
        $mime = '';
        // Check first for the finfo functions needed to use built in functions
        // Suppressing warnings since some versions of PHP are choking on
        // getting the mime type by reading the file contents even though the
        // file is readable
        if (mime_is_detectable_by_finfo()) {
            $finfo = finfo_open(FILEINFO_MIME_TYPE);
            if ($finfo) {
                $mime = @finfo_file($finfo, $file);
                finfo_close($finfo);
            }
        } else {
            // Fall back to our regular way of doing it
            if (function_exists('mime_content_type')) {
                $mime = @mime_content_type($file);
            } elseif (function_exists('ext2mime')) {
                $mime = @ext2mime($file);
            }
        }
        // If mime is empty, set it manually... this can happen from either not
        // being able to detect the mime type using core PHP functions or in the
        // case of a failure of one of the core PHP functions for some reason
        if (empty($mime)) {
            $mime = 'application/octet-stream';
        }
        return $mime;
    }
    return $default;
}