Download a backup zip file.

@param Request $request

@return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\BinaryFileResponse|\Symfony\Component\HttpFoundation\Response
162126
public function download(Request $request)
    {
        $disk = $request->get('disk');
        $file = $request->get('file');

        $storage = Storage::disk($disk);

        $fullPath = $storage->getDriver()->getAdapter()->applyPathPrefix($file);

        if (File::isFile($fullPath)) {
            return response()->download($fullPath);
        }

        return response('', 404);
    }
711742
public function toResponse($request)
    {
        $downloadHeaders = [
            'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
            'Content-Type' => $this->mime_type,
            'Content-Length' => $this->size,
            'Content-Disposition' => 'attachment; filename="'.$this->file_name.'"',
            'Pragma' => 'public',
        ];

        return response()->stream(function () {
            $stream = $this->stream();

            fpassthru($stream);

            if (is_resource($stream)) {
                fclose($stream);
            }
        }, 200, $downloadHeaders);
    }
1323453
public function fetchArchiveAction(Request $request)
    {
        $url = $request->request->get('url');

        $file = file_get_contents($url);
        $tmp = @tempnam('claro', '_zip');
        file_put_contents($tmp, $file);
        $file = new File($tmp);
        $object = $this->fileUtils->createFile($file);
        $archive = $this->serializer->serialize($object);
        $zip = new \ZipArchive();
        $zip->open($this->fileUtils->getPath($object));
        $json = $zip->getFromName('workspace.json');
        $zip->close();

        $data = json_decode($json, true);
        $data['archive'] = $archive;

        return new JsonResponse($data);
    }
759009
public function downloadAction(Request $request)
    {
        /**
         * @var \Ekyna\Bundle\MediaBundle\Model\MediaInterface $media
         * @var \League\Flysystem\File $file
         */
        list($media, $file) = $this->findMedia($request->attributes->get('key'));

        $lastModified = $media->getUpdatedAt();

        $response = new Response();
        $response->setPublic();
        $response->setLastModified($lastModified);
        $response->setEtag(md5($file->getPath().$lastModified->getTimestamp()));
        if ($response->isNotModified($request)) {
            return $response;
        }

        $response = new StreamedResponse();
        $response->setPublic();
        $response->setLastModified($lastModified);
        $response->setEtag(md5($file->getPath().$lastModified->getTimestamp()));

        // Set the headers
        $response->headers->set('Content-Type', $file->getMimetype());
        $response->headers->set('Content-Length', $file->getSize());

        $response->setCallback(function () use ($file) {
            fpassthru($file->readStream());
        });

        return $response;
    }
891633
public function get_file(Request $request)
    {
        $filepath = $request->input('filepath');
        $data = file_get_contents(base_path($filepath));
        echo $data;
    }
1298692
public function get_dir(Request $request)
    {

        $root = base_path() . DIRECTORY_SEPARATOR;
        $postDir = rawurldecode(base_path($request->get('dir')));

        if (file_exists($postDir))
        {
            $files = scandir($postDir);
            $returnDir = substr($postDir, strlen($root));
            natcasesort($files);

            if (count($files) > 2)
            { // The 2 accounts for . and ..
                echo "<ul class='jqueryFileTree'>";
                foreach ($files as $file)
                {
                    $htmlRel = htmlentities($returnDir . $file);
                    $htmlName = htmlentities($file);
                    $ext = preg_replace('/^.*\./', '', $file);
                    if (file_exists($postDir . $file) && $file != '.' && $file != '..')
                    {
                        if (is_dir($postDir . $file))
                        {
                            echo "<li class='directory collapsed'><a rel='" . $htmlRel . "/'>" . $htmlName . "</a></li>";
                        }
                        else
                        {
                            echo "<li class='file ext_{$ext}'><a rel='" . $htmlRel . "'>" . $htmlName . "</a></li>";
                        }
                    }
                }
                echo "</ul>";
            }
        }
    }
621223
public function downloadAction($archive)
    {
        $file = $this->archivePath.DIRECTORY_SEPARATOR.$archive;

        $response = new BinaryFileResponse($file, 200, ['Content-Disposition' => "attachment; filename={$file}"]);

        return $response;
    }
352859
public function save_file(Request $request)
    {
        $filepath = $request->input('filepath');
        $filedata = $request->input('filedata');
        $data = file_put_contents(base_path($filepath), $filedata);
        return response()->json(['success' => true]);
    }
52956
public function localPathFoldersAction(Request $request)
    {
        $form = $this->createForm(new ChoiceLocalPath());
        $form->handleRequest($request);
        $path = $form->get('path')->getData() ?: Filesystem::getUserHomeDir();

        if (($root = $request->get('root')) && strpos($path, $root) !== 0) {
            $path = $root;
        }

        /* @var $response JsonResponse */
        $response = $this->getCacheTimeKeeper()
            ->getResponse([(new \DateTime())->setTimestamp(filemtime($path))], -1, new JsonResponse());
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        return $response->setData([
            'path' => $path,
            'folders' => Filesystem::scandir($path, Filesystem::DIRECTORY),
        ]);
    }
765451
public function loadAction(Request $request)
    {
        $repo = $this->getDoctrine()->getRepository('LibrinfoMediaBundle:File');
        $files = [];

        foreach ($request->get('load_files') as $key => $id) {
            $file = null;

            $dispatcher = $this->get('event_dispatcher');

            $event = new GenericEvent(
                [
                    'request' => $request,
                    'context' => [
                        'key'  => $key,
                        'id'   => $id,
                        'file' => $file,
                    ],
                ], [
                    'file'  => null,
                    'files' => $files,
                ]
            );
            $dispatcher->dispatch(UploadControllerEventListener::PRE_GET_ENTITY, $event);

            $file = $event->getArgument('file');

            if ($file) {
                $file->setFile($file->getBase64File());
            }

            $event = new GenericEvent(
                [
                    'request' => $request,
                    'context' => [
                        'key'  => $key,
                        'id'   => $id,
                        'file' => $file,
                    ],
                ], [
                    'file'  => $file,
                    'files' => $files,
                ]
            );
            $dispatcher->dispatch(UploadControllerEventListener::POST_GET_ENTITY, $event);

            $file = $event->getArgument('file');

            if ($file) {
                $files[] = $file;
            }
        }

        return new JsonResponse($files, 200);
    }
436452
public function checkDownload(Request $request)
    {
        $lst = $request->request->get('lst');
        $ssttid = $request->request->get('ssttid', '');
        $subdefs = $request->request->get('obj', []);

        $download = new \set_export($this->app, $lst, $ssttid);

        if (0 === $download->get_total_download()) {
            $this->app->abort(403);
        }

        $list = $download->prepare_export(
            $this->getAuthenticatedUser(),
            $this->app['filesystem'],
            $subdefs,
            $request->request->get('type') === 'title' ? true : false,
            $request->request->get('businessfields')
        );

        $list['export_name'] = sprintf('%s.zip', $download->getExportName());
        $token = $this->getTokenManipulator()->createDownloadToken($this->getAuthenticatedUser(), serialize($list));
        $this->getDispatcher()->dispatch(PhraseaEvents::EXPORT_CREATE, new ExportEvent(
            $this->getAuthenticatedUser(), $ssttid, $lst, $subdefs, $download->getExportName())
        );

        return $this->app->redirectPath('prepare_download', ['token' => $token->getValue()]);
    }
581484
public function uploadAction(Request $request)
    {
        $this->checkToolAccess();

        $files = $request->files->all();
        $data = null;

        if (1 === count($files)) {
            foreach ($files as $file) {
                $data = file_get_contents($file);
            }
        } else {
            return new JsonResponse('No uploaded file', 500);
        }

        return new JsonResponse($data, 200);
    }
349853
public function send(Request $request)
    {
        $response   = new GetIndexResponse();
        $rpbGetReq  = $this->createRpbMessage($request);
        $rpbGetResp = $this->client->send($rpbGetReq, RiakMessageCodes::YOKOZUNA_INDEX_GET_REQ, RiakMessageCodes::YOKOZUNA_INDEX_GET_RESP);

        if ( ! $rpbGetResp instanceof RpbYokozunaIndexGetResp) {
            return $response;
        }

        if ( ! $rpbGetResp->hasIndex()) {
            return $response;
        }

        $rpbIndex = is_array($rpbGetResp->index)
            ? reset($rpbGetResp->index)
            : $rpbGetResp->index;

        $response->nVal   = $rpbIndex->n_val;
        $response->name   = $rpbIndex->name;
        $response->schema = $rpbIndex->schema;

        return $response;
    }
1298744
public function saveAction(Request $request)
	{
		$file = $this->getEntity();

		// set private
		if ($request->request->has('private')) {
			$private = $request->request->get('private');

			if ($private == 0) {
				$this->getFileStorage()->setPublic($file);
			}

			if ($private == 1) {
				$this->getFileStorage()->setPrivate($file);
			}

			$this->container->getDoctrine()->getManager()->flush();

			return new SupraJsonResponse();
		}

		// renaming
		if ($request->request->has('filename')) {

			$fileName = $request->request->get('filename');

			if (trim($fileName) == '') {
				throw new CmsException(null, 'Empty filename not allowed');
			}

			$newFileInfo = pathinfo($fileName);

			if (mb_strlen($newFileInfo['basename'], 'utf-8') > self::MAX_FILE_BASENAME_LENGTH) {

				if ($file instanceof Folder) {
					throw new CmsException(null, 'Folder name is too long! Maximum length is ' . self::MAX_FILE_BASENAME_LENGTH . ' characters!');
				} else {
					throw new CmsException(null, 'File name is too long! Maximum length is ' . self::MAX_FILE_BASENAME_LENGTH . ' characters!');
				}
			}

			try {
				if ($file instanceof Folder) {
					$this->getFileStorage()->renameFolder($file, $fileName);
				} else {
					$this->getFileStorage()->renameFile($file, $fileName);
				}
			} catch (\Exception $e) {
				$key = $e instanceof UploadFilterException ? $e->getMessageKey() : null;
				throw new CmsException($key, $e->getMessage(), $e);
			}
		}

//		// Custom Properties
//		$dirty = false;
//
//		$propertyConfigurations = $this->getFileStorage()->getCustomPropertyConfigurations();
//		foreach ($propertyConfigurations as $configuration) {
//			$propertyName = $configuration->name;
//
//			if ($request->request->has($propertyName)) {
//				$value = $request->request->get($propertyName);
//
//				$property = $this->getFileStorage()->getFileCustomProperty($file, $propertyName);
//
//				$property->setEditableValue($value, $configuration->getEditable());
//
//				$dirty = true;
//			}
//		}
//
//		if ($dirty) {
//			$this->container->getDoctrine()->getManager()->flush();
//		}

		$response = array();

		// when changing image private attribute, previews and thumbs will change their paths
		// so we will output new image info
		if ($file instanceof File) {
			$response = $this->imageAndFileOutput($file);
		}

		return new SupraJsonResponse($response);
	}
964841
public function trashAction(Request $request): Response
    {
        $form = $this->formFactory->trashLocationWithAsset(
            new LocationTrashWithAssetData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (LocationTrashWithAssetData $data) {
                $location = $data->getLocation();
                $parentLocation = $this->locationService->loadLocation($location->parentLocationId);
                if ($data->getTrashAssets() === LocationTrashWithAssetType::RADIO_SELECT_TRASH_WITH_ASSETS) {
                    $content = $this->contentService->loadContentByContentInfo($location->contentInfo);
                    $relations = $this->contentService->loadRelations($content->versionInfo);
                    $imageLocation = $this->locationService->loadLocation($relations[0]->destinationContentInfo->mainLocationId);
                    $this->trashService->trash($imageLocation);
                }

                $this->trashService->trash($location);

                return $this->redirectToLocation($parentLocation);
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('ezplatform.trash.list'));
    }
429725
public function copyAction(Request $request): Response
    {
        $form = $this->formFactory->copyLocation(
            new LocationCopyData()
        );
        $form->handleRequest($request);

        $location = $form->getData()->getLocation();

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (LocationCopyData $data) {
                $location = $data->getLocation();
                $newParentLocation = $data->getNewParentLocation();

                if (!$newParentLocation->getContent()->getContentType()->isContainer) {
                    throw new InvalidArgumentException(
                        '$newParentLocation',
                        'Cannot copy location to a parent that is not a container'
                    );
                }

                $locationCreateStruct = $this->locationService->newLocationCreateStruct($newParentLocation->id);
                $copiedContent = $this->contentService->copyContent(
                    $location->contentInfo,
                    $locationCreateStruct
                );

                $newLocation = $this->locationService->loadLocation($copiedContent->contentInfo->mainLocationId);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("'%name%' copied to '%location%'") */
                        'location.copy.success',
                        ['%name%' => $location->getContentInfo()->name, '%location%' => $newParentLocation->getContentInfo()->name],
                        'location'
                    )
                );

                return new RedirectResponse($this->generateUrl('_ezpublishLocation', [
                    'locationId' => $newLocation->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('_ezpublishLocation', [
            'locationId' => $location->id,
        ]));
    }
1041104
public function sort(Request $request)
    {
        collect($request->get('files'))
            ->each(function ($sort, $id) {
                $attachment = Attachment::find($id);
                $attachment->sort = $sort;
                $attachment->save();
            });

        return response(200);
    }