PHP 5는 지원이 종료되었으며 2026년 1월 31일에
지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 PHP 5 애플리케이션을 배포할 수 없습니다. 기존 PHP 5 애플리케이션은
지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다.
지원되는 최신 PHP 버전으로 마이그레이션하는 것이 좋습니다.
파일에 대한 공개 액세스 제공
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
일반적으로는 웹을 통해 파일 액세스를 공개할 수 있습니다.
이 작업은 PHP 5 표준 환경에서 다음 방법으로 수행할 수 있습니다.
- 스크립트를 사용하여 Google Cloud Storage에 파일 제공: 앱이 파일을 제공합니다.
- 파일을 직접 제공하여 Google Cloud Storage에서 파일을 제공합니다.
app.yaml
에서 정적 핸들러를 사용하여 앱을 통해 업로드된 파일을 제공합니다.
마지막 방법에는 Cloud Storage가 사용되지 않습니다.
스크립트에서 파일 제공
앱에서 파일을 제공하려면 App Engine CloudStorageTools
클래스를 가져옵니다.
이제 CloudStorageTools::serve를 사용해서 Google Cloud Storage에서 파일을 제공합니다.
이 방식으로 앱에서 파일을 제공하면 개발자가 사용자 ID를 확인하고 허가된 사용자만 파일에 액세스하도록 보장할 수 있습니다. 이 방식의 단점은 파일 제공을 위해 애플리케이션이 이 코드를 실행해야 하기 때문에 인스턴스 시간이 소비되고 그로 인한 비용이 발생하는 것입니다.
Google Cloud Storage에서 직접 파일 제공
위 설명처럼 HTTP를 통해 Cloud Storage에서 파일을 직접 제공하면 앱에서 파일을 제공하는 것보다 속도와 경제성이 높아집니다. 파일을 기록할 때는 익명 사용자가 읽을 수 있도록 파일을 구성해야 합니다. 아래 스니펫에서 볼 수 있듯이 acl
스트림 옵션을 public-read
로 설정합니다.
파일이 공개적으로 읽을 수 있도록 Cloud Storage에 작성되면 CloudStorageTools::getPublicUrl을 사용하여 파일의 공개 URL을 구해야 합니다.
다음 예시에서는 일부 난수가 포함된 공개적으로 읽을 수 있는 파일을 만들고 이를 Cloud Storage 버킷에 기록하며 Cloud Storage에서 해당 파일로 리디렉션합니다.
이 방식의 단점은 파일을 누구나 읽을 수 있기 때문에 파일에 액세스할 수 있는 사람을 제어할 수 없다는 점입니다.
앱을 사용하여 업로드된 파일 제공
파일을 읽고 쓰는 다른 방법이 있나요?에서 이 옵션을 자세하게 설명합니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-04(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThis API supports first-generation runtimes and is applicable when upgrading to corresponding second-generation runtimes, while migration to App Engine PHP 7/8 runtime requires consulting the migration guide.\u003c/p\u003e\n"],["\u003cp\u003eFiles can be made publicly accessible via the web in the PHP 5 standard environment by serving them from a script, serving them directly from Google Cloud Storage, or using the static handler in \u003ccode\u003eapp.yaml\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eServing files from a script through the App Engine \u003ccode\u003eCloudStorageTools\u003c/code\u003e class allows for user identity verification, but it consumes instance hours, and serving directly from Cloud Storage is faster and more cost-effective, but it lacks user access control.\u003c/p\u003e\n"],["\u003cp\u003eTo serve files directly from Cloud Storage, files must be configured as readable by anonymous users, utilizing the \u003ccode\u003epublic-read\u003c/code\u003e ACL setting and \u003ccode\u003eCloudStorageTools::getPublicUrl\u003c/code\u003e to obtain the public URL.\u003c/p\u003e\n"],["\u003cp\u003eServing files uploaded with your app can be achieved, for more details consult the link provided regarding reading and writing files.\u003c/p\u003e\n"]]],[],null,["# Providing Public Access to Files\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| php-gen2\n|\n| /services/access). If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\n\n\u003cbr /\u003e\n\nA common use case is making your files publicly accessible via the web.\nYou can do this in the PHP 5 standard environment in any of these ways:\n\n- Serve files in Google Cloud Storage from a script: your app serves the file.\n- Serve files from Google Cloud Storage, which serves the file directly.\n- Serving files uploaded with your app by using the static handler in `app.yaml`.\n\nNote that the last methodology does not use Cloud Storage.\n\nServing files from a script\n---------------------------\n\nIf you want to serve files from your app, import the App Engine\n`CloudStorageTools` class: \n\n use google\\appengine\\api\\cloud_storage\\CloudStorageTools;\n\nNow use [CloudStorageTools::serve](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.cloud_storage.CloudStorageTools#method_serve)\nto serve the file from Google Cloud Storage: \n\n CloudStorageTools::serve(\"gs://${my_bucket}/serve.txt\");\n\nServing files from the app in this way allows the developer to determine user\nidentity and ensure that only authorised users access the file. The downside\nto this approach is that your application needs to run this code to serve the\nfile, which consumes instance hours and thus incurs cost.\n\nServing files directly from Google Cloud Storage\n------------------------------------------------\n\nThere is a faster and more cost-effective way to serve files than serving them\nfrom the app, as mentioned above: serving them from Cloud Storage directly via\nHTTP. The files need to be configured to be readable by anonymous users at file\nwrite time. As we'll show in the snippet below, you set the `acl` stream option\nto `public-read`.\n\nOnce the file is written to Cloud Storage as publicly readable, you need to\nget the public URL for the file, using\n[CloudStorageTools::getPublicUrl](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.cloud_storage.CloudStorageTools#method_getPublicUrl).\n\nIn the following example, we create a public-readable file containing some\nrandom numbers, writing it to a Cloud Storage bucket, and redirect to\nthat file from Cloud Storage. \n\n $options = ['gs' =\u003e ['acl' =\u003e 'public-read']];\n $context = stream_context_create($options);\n $fileName = \"gs://${my_bucket}/public_file.txt\";\n file_put_contents($fileName, $publicFileText, 0, $context);\n\n $publicUrl = CloudStorageTools::getPublicUrl($fileName, false);\n\nThe limitation of this approach is that there is no control over who can access\nthe file, because the file is readable by anyone.\n\nServing files uploaded with your app\n------------------------------------\n\nThis option is fully described under\n[Is there any other way to read and write files](/appengine/docs/legacy/standard/php/googlestorage#is_there_any_other_way_to_read_and_write_files)."]]