getPath(); //copy the file accross if (copy($sTmpFilePath, $sDocumentFileSystemPath)) { //remove the temporary file unlink($sTmpFilePath); return true; } else { $_SESSION["errorMessage"] = $lang_err_upload; return false; } } /** * Renames a document on the filesystem * * @param object the document to rename * @param string the new document filename * @return true on success, false on failure */ function renamePhysicalDocument($oDocument, $sNewFileName) { global $default; // create new and old paths $sDocumentFileSystemPath = $oDocument->getPath(); $sNewDocumentFileSystemPath = Folder::getFolderPath($oDocument->getFolderID()) . "/" . $sNewFileName; $default->log->debug("renaming $sDocumentFileSystemPath to $sNewDocumentFileSystemPath"); // move it return rename($sDocumentFileSystemPath, $sNewDocumentFileSystemPath); } /** * Stream a document to a client over http * * @param Primary key of document to stream * * @return int number of bytes read from file on success or false otherwise; * * @todo investigate possible problem in MSIE 5.5 concerning Content-Disposition header */ function downloadPhysicalDocument($iDocumentID) { //get the document $oDocument = & Document::get($iDocumentID); //get the path to the document on the server $sDocumentFileSystemPath = $oDocument->getPath(); //set the correct headers Header("Content-Type: " . PhysicalDocumentManager::getMimeTypeName($oDocument->getMimeTypeID())); Header("Content-Length: ". $oDocument->getFileSize()); Header("Content-Disposition: attachment; filename=" . $oDocument->getFileName()); Header("Pragma: no-store"); Header("Expires: 0"); readfile($sDocumentFileSystemPath); } /** * Stream a particular version of a document to a client over http * * @param Primary key of document to stream * @param Primary key of document to stream * @return int number of bytes read from file on success or false otherwise; */ function downloadVersionedPhysicalDocument($iDocumentID, $sVersion) { //get the document $oDocument = & Document::get($iDocumentID); //get the path to the document on the server $sDocumentFileSystemPath = $oDocument->getPath() . "-$sVersion"; //set the correct headers Header("Content-Type: " . PhysicalDocumentManager::getMimeTypeName($oDocument->getMimeTypeID())); header("Content-Length: ". $oDocument->getFileSize()); header("Content-Disposition: attachment; filename=" . "$sVersion-" . $oDocument->getFileName()); header("Pragma: no-store"); header("Expires: 0"); readfile($sDocumentFileSystemPath); } /** * Move a document from a source to a destination * * return boolean true on successful move, false otherwhise * */ function move($sOldDocumentPath, $sNewDocumentPath) { global $lang_fileexists, $lang_err_upload, $lang_err_database; //copy the file to the new destination if (copy($sOldDocumentPath, $sNewDocumentPath)) { //delete the old one unlink($sOldDocumentPath); return true; } else { $_SESSION["errorMessage"] = $lang_err_upload; return false; } } /** * View a document using an inline viewer * * @param Primary key of document to view * * @return int number of bytes read from file on success or false otherwise; * * @todo investigate possible problem in MSIE 5.5 concerning Content-Disposition header */ function inlineViewPhysicalDocument($iDocumentID) { //get the document $oDocument = & Document::get($iDocumentID); //get the path to the document on the server $sDocumentFileSystemPath = $oDocument->getPath(); Header("Content-Type: " . PhysicalDocumentManager::getMimeTypeName($oDocument->getMimeTypeID())); Header("Content-Length: " . $oDocument->getFileSize()); Header("Content-Disposition: inline; filename=" . $oDocument->getFileName()); header("Pragma: no-store"); return readfile($sDocumentFileSystemPath); } /** * Get the uploaded file information and place it into a document object * * @param Array containing uploaded file information (use $aFileArray) * par Primary key of folder into which document will be placed * * @return Document Document object containing uploaded file information */ function & createDocumentFromUploadedFile($aFileArray, $iFolderID) { //get the uploaded document information and put it into a document object $oDocument = & new Document(stripslashes($aFileArray['name']), stripslashes($aFileArray['name']), $aFileArray['size'], $_SESSION["userID"], PhysicalDocumentManager::getMimeTypeID($aFileArray['type'], $aFileArray['name']), $iFolderID); return $oDocument; } /** * Get the mime type primary key for a specific mime type * * @param mime type * * @return int mime type primary key if found, else default mime type primary key (text/plain) */ function getMimeTypeID($sMimeType, $sFileName) { global $default; $sql = $default->db; // check by file extension $sExtension = strtolower(substr($sFileName, strpos($sFileName, ".")+1, strlen($sFileName) - strpos($sFileName, "."))); $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE LOWER(filetypes) = '$sExtension'"); if ($sql->next_record()) { return $sql->f("id"); } //get the mime type if (isset($sMimeType)) { $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE mimetypes = '$sMimeType'"); if ($sql->next_record()) { //get the mime type id return $sql->f("id"); } } //otherwise return the default mime type return PhysicalDocumentManager::getDefaultMimeTypeID(); } /** * Get the default mime type, which is text/plain * * @return int default mime type * */ function getDefaultMimeTypeID() { global $default; $sql = $default->db; $sql->query("SELECT id FROM " . $default->owl_mime_table . " WHERE mimetypes = 'text/plain'"); $sql->next_record(); //get the mime type id return $sql->f("id"); } function getMimeTypeName($iMimeTypeID) { global $default; $sql = $default->db; $sql->query("SELECT mimetypes FROM " . $default->owl_mime_table . " WHERE id = " . $iMimeTypeID); if ($sql->next_record()) { return $sql->f("mimetypes"); } return "application/octet-stream"; } } ?>