public function testGuessMimeTypeHasRightReturn() { $this->assertEquals("unknown/", $this->stub->guessMimeType("test")); $this->assertEquals("application/x-javascript", $this->stub->guessMimeType("test.js")); $this->assertEquals("application/json", $this->stub->guessMimeType("test.json")); $this->assertEquals("image/jpg", $this->stub->guessMimeType("test.jpg")); $this->assertEquals("image/jpg", $this->stub->guessMimeType("test.jpeg")); $this->assertEquals("image/jpg", $this->stub->guessMimeType("test.jpe")); $this->assertEquals("image/png", $this->stub->guessMimeType("test.png")); $this->assertEquals("image/gif", $this->stub->guessMimeType("test.gif")); $this->assertEquals("image/bmp", $this->stub->guessMimeType("test.bmp")); $this->assertEquals("image/tiff", $this->stub->guessMimeType("test.tiff")); $this->assertEquals("image/tif", $this->stub->guessMimeType("test.tif")); $this->assertEquals("text/css", $this->stub->guessMimeType("test.css")); $this->assertEquals("application/xml", $this->stub->guessMimeType("test.xml")); $this->assertEquals("application/msword", $this->stub->guessMimeType("test.doc")); $this->assertEquals("application/msword", $this->stub->guessMimeType("test.docx")); $this->assertEquals("application/msword", $this->stub->guessMimeType("test.dot")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xls")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xlt")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xlm")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xld")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xla")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xlc")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xlw")); $this->assertEquals("application/vnd.ms-excel", $this->stub->guessMimeType("test.xll")); $this->assertEquals("application/vnd.oasis.opendocument.text", $this->stub->guessMimeType("test.odt")); $this->assertEquals("application/vnd.ms-powerpoint", $this->stub->guessMimeType("test.ppt")); $this->assertEquals("application/vnd.ms-powerpoint", $this->stub->guessMimeType("test.pps")); $this->assertEquals("application/rtf", $this->stub->guessMimeType("test.rtf")); $this->assertEquals("application/pdf", $this->stub->guessMimeType("test.pdf")); $this->assertEquals("text/html", $this->stub->guessMimeType("test.html")); $this->assertEquals("text/html", $this->stub->guessMimeType("test.htm")); $this->assertEquals("text/html", $this->stub->guessMimeType("test.php")); $this->assertEquals("text/plain", $this->stub->guessMimeType("test.txt")); $this->assertEquals("text/plain", $this->stub->guessMimeType("test.ini")); $this->assertEquals("video/mpeg", $this->stub->guessMimeType("test.mpeg")); $this->assertEquals("video/mpeg", $this->stub->guessMimeType("test.mpg")); $this->assertEquals("video/mpeg", $this->stub->guessMimeType("test.mpe")); $this->assertEquals("audio/mpeg3", $this->stub->guessMimeType("test.mp3")); $this->assertEquals("audio/wav", $this->stub->guessMimeType("test.wav")); $this->assertEquals("audio/aiff", $this->stub->guessMimeType("test.aiff")); $this->assertEquals("audio/aiff", $this->stub->guessMimeType("test.aif")); $this->assertEquals("video/msvideo", $this->stub->guessMimeType("test.avi")); $this->assertEquals("video/x-ms-wmv", $this->stub->guessMimeType("test.wmv")); $this->assertEquals("video/quicktime", $this->stub->guessMimeType("test.mov")); $this->assertEquals("application/zip", $this->stub->guessMimeType("test.zip")); $this->assertEquals("application/x-tar", $this->stub->guessMimeType("test.tar")); $this->assertEquals("application/x-shockwave-flash", $this->stub->guessMimeType("test.swf")); $this->assertEquals("application/vnd.lotus-notes", $this->stub->guessMimeType("test.nfs")); $this->assertEquals("application/vnd.sante400", $this->stub->guessMimeType("test.spl")); $this->assertEquals("application/vnd.sante400", $this->stub->guessMimeType("test.rlb")); $this->assertEquals("image/svg+xml", $this->stub->guessMimeType("test.svg")); }
/** * @see parent::doStore() */ function doStore() { $upload = null; if (CValue::POST("_from_yoplet") == 1) { /** @var CFile $obj */ $obj = $this->_obj; $array_file_name = array(); $path = CAppUI::conf("dPfiles yoplet_upload_path"); if (!$path) { $path = "tmp"; } // On retire les backslashes d'escape $file_name = stripslashes($this->request['_file_path']); // Récupération du nom de l'image en partant de la fin de la chaîne // et en rencontrant le premier \ ou / preg_match('@[\\\\/]([^\\\\/]*)$@i', $file_name, $array_file_name); $file_name = $array_file_name[1]; $extension = strrchr($file_name, '.'); $_rename = $this->request['_rename'] ? $this->request['_rename'] : 'upload'; $file_path = "{$path}/" . $this->request['_checksum']; $obj->file_name = $_rename == 'upload' ? $file_name : $_rename . $extension; $obj->_old_file_path = $this->request['_file_path']; $obj->doc_size = filesize($file_path); $obj->author_id = CAppUI::$user->_id; if (CModule::getActive("cda")) { $obj->type_doc = $this->request["type_doc"]; } $obj->fillFields(); $obj->updateFormFields(); $obj->file_type = CMbPath::guessMimeType($file_name); if ($msg = $obj->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } else { $obj->forceDir(); $obj->moveFile($file_path); } return parent::doStore(); } $_file_category_id = CValue::post("_file_category_id"); $language = CValue::post("language"); $type_doc = CValue::post("type_doc"); $named = CValue::post("named"); $rename = CValue::post("_rename"); CValue::setSession("_rename", $rename); if (isset($_FILES["formfile"])) { $aFiles = array(); $upload =& $_FILES["formfile"]; foreach ($upload["error"] as $fileNumber => $etatFile) { if (!$named) { $rename = $rename ? $rename . strrchr($upload["name"][$fileNumber], '.') : ""; } if ($upload["name"][$fileNumber]) { $aFiles[] = array("_mode" => "file", "name" => $upload["name"][$fileNumber], "type" => CMbPath::guessMimeType($upload["name"][$fileNumber]), "tmp_name" => $upload["tmp_name"][$fileNumber], "error" => $upload["error"][$fileNumber], "size" => $upload["size"][$fileNumber], "language" => $language, "type_doc" => $type_doc, "file_category_id" => $_file_category_id, "object_id" => CValue::post("object_id"), "object_class" => CValue::post("object_class"), "_rename" => $rename); } } // Pasted images, via Data uri if (!empty($_POST["formdatauri"])) { $data_uris = $_POST["formdatauri"]; $data_names = $_POST["formdatauri_name"]; foreach ($data_uris as $fileNumber => $fileContent) { $parsed = $this->parseDataUri($fileContent); $_name = $data_names[$fileNumber]; if (!$named) { $ext = strrchr($_name, '.'); if ($ext === false) { $ext = "." . substr(strrchr($parsed["mime"], '/'), 1); $_name .= $ext; } $rename = $rename ? $rename . $ext : ""; } $temp = tempnam(sys_get_temp_dir(), "up_"); file_put_contents($temp, $parsed["data"]); if ($data_names[$fileNumber]) { $aFiles[] = array("_mode" => "datauri", "name" => $_name, "type" => $parsed["mime"], "tmp_name" => $temp, "error" => 0, "size" => strlen($parsed["data"]), "language" => $language, "type_doc" => $type_doc, "file_category_id" => $_file_category_id, "object_id" => CValue::post("object_id"), "object_class" => CValue::post("object_class"), "_rename" => $rename); } } } $merge_files = CValue::post("_merge_files"); if ($merge_files) { $pdf = new CMbPDFMerger(); $this->_obj = new $this->_obj->_class(); /** @var CFile $obj */ $obj = $this->_obj; $file_name = ""; $nb_converted = 0; foreach ($aFiles as $key => $file) { $converted = 0; if ($file["error"] == UPLOAD_ERR_NO_FILE) { continue; } if ($file["error"] != 0) { CAppUI::setMsg(CAppUI::tr("CFile-msg-upload-error-" . $file["error"]), UI_MSG_ERROR); continue; } // Si c'est un pdf, on le rajoute sans aucun traitement if (substr(strrchr($file["name"], '.'), 1) == "pdf") { $file_name .= substr($file["name"], 0, strpos($file["name"], '.')); $pdf->addPDF($file["tmp_name"], 'all'); $nb_converted++; $converted = 1; } else { if ($obj->isPDFconvertible($file["name"]) && $obj->convertToPDF($file["tmp_name"], $file["tmp_name"] . "_converted")) { $pdf->addPDF($file["tmp_name"] . "_converted", 'all'); $file_name .= substr($file["name"], 0, strpos($file["name"], '.')); $nb_converted++; $converted = 1; } else { $other_file = new CFile(); $other_file->bind($file); $other_file->file_name = $file["name"]; $other_file->file_type = $file["type"]; $other_file->doc_size = $file["size"]; $other_file->fillFields(); $other_file->private = CValue::post("private"); if (false == ($res = $other_file->moveTemp($file))) { CAppUI::setMsg("Fichier non envoyé", UI_MSG_ERROR); continue; } $other_file->author_id = CAppUI::$user->_id; if ($msg = $other_file->store()) { CAppUI::setMsg("Fichier non enregistré: {$msg}", UI_MSG_ERROR); continue; } CAppUI::setMsg("Fichier enregistré", UI_MSG_OK); } } // Pour le nom du pdf de fusion, on concatène les noms des fichiers if ($key != count($aFiles) - 1 && $converted) { $file_name .= "-"; } } // Si des fichiers ont été convertis et ajoutés à PDFMerger, // création du cfile. if ($nb_converted) { $obj->file_name = $file_name . ".pdf"; $obj->file_type = "application/pdf"; $obj->author_id = CAppUI::$user->_id; $obj->private = CValue::post("private"); $obj->object_id = CValue::post("object_id"); $obj->object_class = CValue::post("object_class"); $obj->updateFormFields(); $obj->fillFields(); $obj->forceDir(); $tmpname = tempnam("/tmp", "pdf_"); $pdf->merge('file', $tmpname); $obj->doc_size = strlen(file_get_contents($tmpname)); $obj->moveFile($tmpname); //rename($tmpname, $obj->_file_path . "/" .$obj->file_real_filename); if ($msg = $obj->store()) { CAppUI::setMsg("Fichier non enregistré: {$msg}", UI_MSG_ERROR); } else { CAppUI::setMsg("Fichier enregistré", UI_MSG_OK); } } } else { foreach ($aFiles as $file) { if ($file["error"] == UPLOAD_ERR_NO_FILE) { continue; } if ($file["error"] != 0) { CAppUI::setMsg(CAppUI::tr("CFile-msg-upload-error-" . $file["error"]), UI_MSG_ERROR); continue; } // Reinstanciate $this->_obj = new $this->_obj->_class(); /** @var CFile $obj */ $obj = $this->_obj; $obj->bind($file); $obj->file_name = empty($file["_rename"]) ? $file["name"] : $file["_rename"]; $obj->file_type = $file["type"]; if ($obj->file_type == "application/x-download") { $obj->file_type = CMbPath::guessMimeType($obj->file_name); } $obj->doc_size = $file["size"]; $obj->fillFields(); $obj->private = CValue::post("private"); if ($file["_mode"] == "file") { $res = $obj->moveTemp($file); } else { $res = $obj->moveFile($file["tmp_name"]); } if (false == $res) { CAppUI::setMsg("Fichier non envoyé", UI_MSG_ERROR); continue; } // File owner on creation if (!$obj->file_id) { $obj->author_id = CAppUI::$user->_id; } if ($msg = $obj->store()) { CAppUI::setMsg("Fichier non enregistré: {$msg}", UI_MSG_ERROR); continue; } CAppUI::setMsg("Fichier enregistré", UI_MSG_OK); } } // Redaction du message et renvoi if (CAppUI::isMsgOK() && $this->redirectStore) { $this->redirect =& $this->redirectStore; } if (!CAppUI::isMsgOK() && $this->redirectError) { $this->redirect =& $this->redirectError; } } else { parent::doStore(); } }
<?php /** * $Id$ * * @category Files * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ CCanDo::checkEdit(); $object_class = CValue::post("object_class"); $object_id = CValue::post("object_id"); $content = CValue::post("content"); $file_name = CValue::post("file_name"); $file = new CFile(); $file->file_name = $file_name; $file->object_class = $object_class; $file->object_id = $object_id; $file->fillFields(); $file->putContent(base64_decode($content)); $file->file_type = CMbPath::guessMimeType($file_name); if ($msg = $file->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } else { CAppUI::setMsg("CFile-msg-moved"); } echo CAppUI::getMsg();
$url = CValue::get('url'); $format = CValue::get('format'); if (!$file_id && !$url) { return ""; } if ($file_id) { $file = new CFile(); $file->load($file_id); $file->canDo(); if (!$file->_can->read) { return ""; } //@TODO le faire marcher avec du datauri if (strpos($file->file_type, "svg") !== false) { echo json_encode("?m=files&a=fileviewer&file_id={$file->_id}&phpTumb=1&suppressHeaders=1"); CApp::rip(); //echo CApp::json(file_get_contents($file->_file_path)); } elseif ($format == 'uri') { $data = $file->getDataURI(); CApp::json($data); } } elseif ($url) { $mime_type = CMbPath::guessMimeType($url); $content = @file_get_contents($url); if ($content) { $data = "data:" . $mime_type . ";base64," . urlencode(base64_encode($content)); CApp::json($data); } else { return ""; } }
/** * $Id: do_select_supervision_picture.php 26555 2014-12-23 12:48:14Z flaviencrochard $ * * @category Patients * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision: 26555 $ * @link http://www.mediboard.org */ CCanDo::checkAdmin(); $path = str_replace("..", "", CValue::post("path")); $timed_picture_id = CValue::post("timed_picture_id"); if (is_file($path) && strpos(CSupervisionTimedPicture::PICTURES_ROOT, $path) !== 0) { $timed_picture = new CSupervisionTimedPicture(); $timed_picture->load($timed_picture_id); $file = new CFile(); $file->setObject($timed_picture); $file->fillFields(); $file->file_name = basename($path); $file->doc_size = filesize($path); $file->file_type = CMbPath::guessMimeType($path); $file->moveFile($path, false, true); if ($msg = $file->store()) { CAppUI::setMsg($msg, UI_MSG_WARNING); } else { CAppUI::setMsg("Image enregistrée"); } } echo CAppUI::getMsg(); CApp::rip();