$prefix = "file/"; // if previous file, delete it if ($new_file == false) { $filename = $file->getFilenameOnFilestore(); if (file_exists($filename)) { unlink($filename); } // use same filename on the disk - ensures thumbnails are overwritten $filestorename = $file->getFilename(); $filestorename = elgg_substr($filestorename, elgg_strlen($prefix)); } else { $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']); } $file->setFilename($prefix . $filestorename); $file->originalfilename = $_FILES['upload']['name']; $mime_type = $file->detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']); // hack for Microsoft zipped formats $info = pathinfo($_FILES['upload']['name']); $office_formats = array('docx', 'xlsx', 'pptx'); if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) { switch ($info['extension']) { case 'docx': $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break; case 'xlsx': $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; case 'pptx': $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break; }