Jarves\Controller\Admin\FileController::prepareUploadAction PHP Method

prepareUploadAction() public method

public prepareUploadAction ( FOS\RestBundle\Request\ParamFetcher $paramFetcher ) : array[renamed
$paramFetcher FOS\RestBundle\Request\ParamFetcher
return array[renamed
    public function prepareUploadAction(ParamFetcher $paramFetcher)
    {
        $path = $paramFetcher->get('path');
        $name = $paramFetcher->get('name');
        $overwrite = filter_var($paramFetcher->get('overwrite'), FILTER_VALIDATE_BOOLEAN);
        $autoRename = filter_var($paramFetcher->get('autoRename'), FILTER_VALIDATE_BOOLEAN);
        $oriName = $name;
        $newPath = $path == '/' ? '/' . $name : $path . '/' . $name;
        $overwrite = filter_var($overwrite, FILTER_VALIDATE_BOOLEAN);
        $autoRename = filter_var($autoRename, FILTER_VALIDATE_BOOLEAN);
        $this->checkAccess($path);
        $res = array();
        if ($name != $oriName) {
            $res['renamed'] = true;
            $res['name'] = $name;
        }
        $exist = $this->webFilesystem->has($newPath);
        if ($exist && !$overwrite) {
            if ($autoRename) {
                //find new name
                $extension = '';
                $firstName = $oriName;
                $lastDot = strrpos($oriName, '.');
                if (false !== $lastDot) {
                    $firstName = substr($oriName, 0, $lastDot);
                    $extension = substr($oriName, $lastDot + 1);
                }
                $i = 0;
                do {
                    $i++;
                    $name = $firstName . '-' . $i . ($extension ? '.' . $extension : '');
                    $newPath = $path == '/' ? '/' . $name : $path . '/' . $name;
                    if (!$this->webFilesystem->has($newPath)) {
                        break;
                    }
                } while (true);
                $res['renamed'] = true;
                $res['name'] = $name;
            } else {
                $res['exist'] = true;
                return $res;
            }
        }
        $this->webFilesystem->write($newPath, "file-is-being-uploaded-by-" . hash('sha512', $this->pageStack->getSession()->getId()));
        $res['ready'] = true;
        return $res;
    }