function returnFile($in, $out, $ext)
{
    header("Pragma: public");
    header("Content-type: " . ext2mime($ext));
    header('Content-Disposition: ' . ($ext == 'pdf' ? 'inline' : 'attachment') . '; filename="' . addslashes($out) . '"');
    if (is_file($in)) {
        header('Content-Length: ' . filesize($in));
        readfile($in);
    } else {
        header('Content-Length: ' . strlen($in));
        echo $in;
    }
}
Example #2
0
 /**
  * Determines MIME-type encoding as possible.
  * @param string $fileLocation relative path to file
  * @return string MIME-type
  */
 function email2GetMime($fileLocation)
 {
     if (!is_readable($fileLocation)) {
         return 'application/octet-stream';
     }
     if (function_exists('mime_content_type')) {
         $mime = mime_content_type($fileLocation);
     } elseif (function_exists('ext2mime')) {
         $mime = ext2mime($fileLocation);
     } else {
         $mime = 'application/octet-stream';
     }
     return $mime;
 }
Example #3
0
 /**
  * Get MIME type for uploaded file
  * @param array $_FILES_element $_FILES element required
  * @return string MIME type
  */
 function getMime($_FILES_element)
 {
     $filename = $_FILES_element['name'];
     $file_ext = pathinfo($filename, PATHINFO_EXTENSION);
     //If no file extension is available and the mime is octet-stream try to determine the mime type.
     $recheckMime = empty($file_ext) && !empty($_FILES_element['type']) && $_FILES_element['type'] == 'application/octet-stream';
     if (!empty($_FILES_element['type']) && !$recheckMime) {
         $mime = $_FILES_element['type'];
     } elseif (function_exists('mime_content_type')) {
         $mime = mime_content_type($_FILES_element['tmp_name']);
     } elseif (function_exists('ext2mime')) {
         $mime = ext2mime($_FILES_element['name']);
     } else {
         $mime = 'application/octet-stream';
     }
     return $mime;
 }
Example #4
0
 /**
  * Get MIME type for uploaded file
  * @param array $_FILES_element $_FILES element required
  * @return string MIME type
  */
 function getMime($_FILES_element)
 {
     $filename = $_FILES_element['name'];
     $filetype = isset($_FILES_element['type']) ? $_FILES_element['type'] : null;
     $file_ext = pathinfo($filename, PATHINFO_EXTENSION);
     $is_image = strpos($filetype, 'image/') === 0;
     // if it's an image, or no file extension is available and the mime is octet-stream
     // try to determine the mime type
     $recheckMime = $is_image || empty($file_ext) && $filetype == 'application/octet-stream';
     $mime = 'application/octet-stream';
     if ($filetype && !$recheckMime) {
         $mime = $filetype;
     } elseif (function_exists('mime_content_type')) {
         $mime = mime_content_type($_FILES_element['tmp_name']);
     } elseif ($is_image) {
         $info = getimagesize($_FILES_element['tmp_name']);
         if ($info) {
             $mime = $info['mime'];
         }
     } elseif (function_exists('ext2mime')) {
         $mime = ext2mime($filename);
     }
     return $mime;
 }
Example #5
0
 /**
  * Get mime types of file if function mime_content_type dont exist or not recognize type
  * @param string $filename
  * @return string
  * 	return mime type of file
  */
 public static function getMimeType($filename)
 {
     if (function_exists('mime_content_type')) {
         $mime = mime_content_type($filename);
     } elseif (function_exists('ext2mime')) {
         $mime = ext2mime($filename);
     }
     if (empty($mime)) {
         $ext = strtolower(array_pop(explode('.', $filename)));
         if (array_key_exists($ext, self::$extMimeTypes)) {
             $mime = self::$extMimeTypes[$ext];
         } else {
             $mime = 'application/octet-stream';
         }
     }
     return $mime;
 }
 function getMime(&$_FILES_element)
 {
     $filename = $_FILES_element['name'];
     if ($_FILES_element['type']) {
         $mime = $_FILES_element['type'];
     } elseif (function_exists('mime_content_type')) {
         $mime = mime_content_type($_FILES_element['tmp_name']);
     } elseif (function_exists('ext2mime')) {
         $mime = ext2mime($_FILES_element['name']);
     } else {
         $mime = ' application/octet-stream';
     }
     return $mime;
 }
Example #7
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;
}
function set_file_attachment($session, $file)
{
    global $db;
    require_once 'soap/config_upload.php';
    // require_once ('base.php');
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    $AppUI =& $_SESSION['AppUI'];
    $GLOBALS['AppUI'] = $AppUI;
    $module_name = 'files';
    $perms =& $AppUI->acl();
    $canAccess = $perms->checkModule($module_name, 'access');
    $canAuthor = $perms->checkModule($module_name, 'add');
    $GLOBALS['perms'] = $perms;
    if (!$canAccess || !$canAuthor) {
        $error->set_error('no_access');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    $modclass = $AppUI->getModuleClass($module_name);
    if (file_exists($modclass)) {
        include_once $modclass;
    } else {
        $error->set_error('no_module');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    $module_name = 'tasks';
    $modclass = $AppUI->getModuleClass($module_name);
    if (file_exists($modclass)) {
        include_once $modclass;
    } else {
        $error->set_error('no_module');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    $focus = new CFile();
    $task = new CTask();
    $task->load($file['task_id']);
    /// $error->description.=$file['location'];
    //$file['location'] = base64_decode($file['location']);
    //$file['filename'] = base64_decode($file['filename']);
    /*if (filesize($file['location'] > $config_upload['upload_maxsize']){
         $error->set_error('no_file');
         return array('id'=>-1, 'error'=>$error->get_soap_array());
      }*/
    $file_real_filename = uniqid(rand());
    $new_location = DP_BASE_DIR . '/files/' . $task->task_project . '/' . $file_real_filename;
    /// $error->description.=$new_location;
    if (!is_dir(DP_BASE_DIR . '/files/' . $task->task_project)) {
        mkdir(DP_BASE_DIR . '/files/' . $task->task_project);
    }
    copy($file['location'], $new_location);
    if (file_exists($new_location)) {
        //  return array('id'=>$new_location, 'error'=>$error->get_soap_array());
        if (!empty($file['filename'])) {
            $upload_filename = $file['filename'];
            $ext_pos = strrpos($upload_filename, ".");
            $file_ext = substr($upload_filename, $ext_pos + 1);
            // $error->description.="file_ext: ".$file_ext;
            // return array('id'=>-1, 'error'=>$error->get_soap_array());
            /* if (in_array($file_ext, $config_upload['upload_badext'])) {
                  $upload_filename .= ".txt";
                  $file_ext = "txt";
               }*/
            $focus->file_name = $upload_filename;
            $focus->file_owner = $AppUI->user_id;
            // $error->description.="file_owner_id: ".$AppUI->user_id;
            $focus->file_real_filename = $file_real_filename;
            $focus->file_project = $task->task_project;
            $focus->file_date = str_replace("'", '', $db->DBTimeStamp(time()));
            // $error->description.="file_task_id: ".$task->task_id;
            $focus->file_task = $task->task_id;
            $focus->file_folder = 0;
            $focus->file_size = filesize($new_location);
            $focus->file_parent = 0;
            $focus->file_folder = 0;
            $focus->file_version = 1;
            $focus->file_version_id = getNextVersionID();
            $focus->file_category = 1;
            $focus->file_type = ext2mime($file_ext);
            $focus->store();
            //  $error->description.="file_file: ".$focus->file_type;
        } else {
            $error->set_error('no_file');
            return array('id' => -1, 'error' => $error->get_soap_array());
        }
    } else {
        $error->set_error('no_file');
        return array('id' => -1, 'error' => $error->get_soap_array());
    }
    return array('id' => $focus->file_id, 'error' => $error->get_soap_array());
}