/** * @covers Xoops\Core\MimeTypes::findType */ public function testFindType() { $this->assertEquals('text/plain', MimeTypes::findType('txt'), 'get mimetype for .txt extension'); $this->assertEquals('image/jpeg', MimeTypes::findType('jpg'), 'get mimetype for .jpg extension'); $this->assertEquals('image/jpeg', MimeTypes::findType('jpeg'), 'get mimetype for .jpeg extension'); $this->assertNull(MimeTypes::findType('failme-no-such-extension'), 'get mimetype for garbage extension'); }
/** * Fetch the uploaded file * * @param string $media_name Name of the file field * @param int $index Index of the file (if more than one uploaded under that name) * * @return bool */ public function fetchMedia($media_name, $index = null) { if (!isset($_FILES[$media_name])) { $this->setErrors(\XoopsLocale::E_FILE_NOT_FOUND); return false; } else { if (is_array($_FILES[$media_name]['name']) && isset($index)) { $index = (int) $index; $this->mediaName = get_magic_quotes_gpc() ? stripslashes($_FILES[$media_name]['name'][$index]) : $_FILES[$media_name]['name'][$index]; $this->mediaType = $_FILES[$media_name]['type'][$index]; $this->mediaSize = $_FILES[$media_name]['size'][$index]; $this->mediaTmpName = $_FILES[$media_name]['tmp_name'][$index]; $this->mediaError = !empty($_FILES[$media_name]['error'][$index]) ? $_FILES[$media_name]['error'][$index] : 0; } else { $media_name = $_FILES[$media_name]; $this->mediaName = get_magic_quotes_gpc() ? stripslashes($media_name['name']) : $media_name['name']; $this->mediaType = $media_name['type']; $this->mediaSize = $media_name['size']; $this->mediaTmpName = $media_name['tmp_name']; $this->mediaError = !empty($media_name['error']) ? $media_name['error'] : 0; } } $path_parts = pathinfo($this->mediaName); $ext = isset($path_parts['extension']) ? $path_parts['extension'] : ''; $this->mediaRealType = \Xoops\Core\MimeTypes::findType($ext); $this->errors = array(); if ((int) $this->mediaSize < 0) { $this->setErrors(\XoopsLocale::E_INVALID_FILE_SIZE); return false; } if ($this->mediaName == '') { $this->setErrors(\XoopsLocale::E_FILE_NAME_MISSING); return false; } if ($this->mediaTmpName == 'none' || !is_uploaded_file($this->mediaTmpName)) { $this->setErrors(\XoopsLocale::NO_FILE_UPLOADED); return false; } if ($this->mediaError > 0) { $this->setErrors(sprintf(\XoopsLocale::EF_UNEXPECTED_ERROR, $this->mediaError)); return false; } return true; }
break; } $qrCode->setErrorCorrection($ec); $qrCode->setModuleSize((int) $configs['qrcode_mps'] - 1); $qrCode->setPadding($configs['qrcode_margin'] * $qrCode->getModuleSize()); $qrCode->setBackgroundColor(normalizeColor($configs['qrcode_bgcolor'])); $qrCode->setForegroundColor(normalizeColor($configs['qrcode_fgcolor'])); //$qrCode->setText("Life is too short to be generating QR codes"); //$qrCode->setSize(300); try { $qrData = $qrCode->get('png'); } catch (\Exception $e) { $xoopsPreload->triggerEvent('core.exception', $e); $qrData = ''; } $mimetype = \Xoops\Core\MimeTypes::findType('png'); $expires = 60 * 60 * 24 * 15; // seconds, minutes, hours, days header("Cache-Control: public, max-age=" . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); //header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', $mtime)); header('Content-type: ' . $mimetype); echo $qrData; exit; /** * normalizeColor * * @param string $color 24 bit RGB color as hex digit (i.e. 'FFFFFF') * * @return array of ints, RGB color values keyed as 'red', 'green' and 'blue' */
//$file = $xoops->path($path); $mtime = filemtime($file); // Is there really a file to output? if ($mtime === false) { header("HTTP/1.0 404 Not Found"); exit; } if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $mtime) { header('HTTP/1.0 304 Not Modified'); exit; } } $path_parts = pathinfo($file); $ext = isset($path_parts['extension']) ? $path_parts['extension'] : ''; $mimetype = \Xoops\Core\MimeTypes::findType($ext); //Do not output garbage if (empty($mimetype)) { header("HTTP/1.0 404 Not Found"); exit; } // Output now // seconds, minutes, hours, days $expires = 60 * 60 * 24 * 15; //header("Pragma: public"); header("Cache-Control: public, max-age=" . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', $mtime)); header('Content-type: ' . $mimetype); readfile($file); exit;