src/AppBundle/Common/FileToolkit.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace AppBundle\Common;
use AppBundle\Common\Exception\FileToolkitException;
use Imagine\Image\Box;
use Imagine\Image\Point;
use Topxia\Service\Common\ServiceKernel;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class FileToolkit
{
public static function mungeFilename($fileName, $extensions)
{
$original = $fileName;
// Remove any null bytes. See http://php.net/manual/en/security.filesystem.nullbytes.php
$fileName = str_replace(chr(0), '', $fileName);
$whitelist = array_unique(explode(' ', trim($extensions)));
// Split the filename up by periods. The first part becomes the basename
// the last part the final extension.
$fileNameParts = explode('.', $fileName);
$newFilename = array_shift($fileNameParts); // Remove file basename.
$finalExtension = array_pop($fileNameParts);
// Remove final extension.
// Loop through the middle parts of the name and add an underscore to the
// end of each section that could be a file extension but isn't in the list
// of allowed extensions.
foreach ($fileNameParts as $fileNamePart) {
$newFilename .= '.'.$fileNamePart;
if (!in_array($fileNamePart, $whitelist) && preg_match("/^[a-zA-Z]{2,5}\d?$/", $fileNamePart)) {
$newFilename .= '_';
}
}
$fileName = $newFilename.'.'.$finalExtension;
return $fileName;
}
public static function validateFileExtension(File $file, $extensions = array())
{
if (empty($extensions)) {
$extensions = static::getSecureFileExtensions();
}
if ($file instanceof UploadedFile) {
$filename = $file->getClientOriginalName();
} else {
$filename = $file->getFilename();
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。