PHP 5는 지원이 종료되었으며 2026년 1월 31일에 지원 중단됩니다. 지원 중단 후에는 조직에서 이전에 조직 정책을 사용하여 레거시 런타임의 배포를 다시 사용 설정한 경우에도 PHP 5 애플리케이션을 배포할 수 없습니다. 기존 PHP 5 애플리케이션은 지원 중단 날짜 이후에도 계속 실행되고 트래픽을 수신합니다. 지원되는 최신 PHP 버전으로 마이그레이션하는 것이 좋습니다.
Google Cloud Storage를 활성화하고 버킷을 만들어야 합니다. 자세한 내용은 설정을 참조하세요.
지원되는 PHP 5 파일 시스템 함수
일반적으로 사용되는 많은 PHP 5 파일 함수는 파일 정보 및 디렉터리 함수와 함께 지원됩니다. 지원되는 전체 PHP 함수 목록은 PHP 5 파일 시스템 함수 지원을 참조하세요.
Cloud Storage Tools API에서 제공하는 확장 기능
Google Cloud Storage 스트림 래퍼를 사용하면 PHP 파일 시스템 호출을 사용할 수 있습니다. 하지만 Google Cloud Storage를 최적으로 사용하기 위해 필요할 수 있는 확장 기능이 있습니다. 이러한 확장 기능은 Cloud Storage Tools API에서 제공합니다.
이 API는 기타 유용한 유틸리티와 함께 파일 및 이미지 제공을 지원하는 일련의 기능을 제공합니다. 이러한 기능은 나머지 항목 페이지에서 다룹니다.
파일을 읽고 쓰는 다른 방법이 있나요?
App Engine PHP 5 앱은 런타임 시 파일을 쓰려면 Cloud Storage 스트림 래퍼를 사용해야 합니다. 하지만 앱에서 파일을 읽어야 하는데 이러한 파일이 정적인 경우에는 file_get_contents와 같은 PHP 파일 시스템 함수를 사용하여 앱을 통해 업로드된 정적 파일을 선택적으로 읽을 수도 있습니다.
예를 들면 다음과 같습니다.
$fileContents = file_get_contents($filePath);
여기서 지정된 경로는 해당 경로에 액세스하는 스크립트에 상대적인 경로여야 합니다.
앱을 App Engine에 배포할 때는 애플리케이션 하위 디렉터리에 파일을 업로드해야 하며, 앱에서 해당 파일에 액세스할 수 있도록 app.yaml 파일을 구성해야 합니다. 자세한 내용은 app.yaml로 PHP 5 애플리케이션 구성을 참조하세요.
app.yaml 구성에서 정적 파일 또는 디렉터리 핸들러(static_files 또는 static_dir)를 사용하려면 application_readable을 true로 설정해야 합니다. 그렇지 않으면 앱에서 파일을 읽을 수 없습니다.
하지만 script 핸들러가 이 파일을 제공하는 경우 기본적으로 스크립트 핸들러가 이러한 파일을 읽을 수 있으므로 이 작업을 수행할 필요가 없습니다.
다음에 수행할 작업
Cloud Storage Tools API 사용에 대한 세부정보를 보려면 다음 항목을 읽어보세요.
[[["이해하기 쉬움","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 can be used when upgrading to corresponding second-generation runtimes, with a migration guide available for PHP 7/8 runtime updates.\u003c/p\u003e\n"],["\u003cp\u003eIn the Google App Engine PHP 5 Standard Environment, the local filesystem is not writeable to ensure application security and scalability, necessitating the use of the built-in Google Cloud Storage stream wrapper for file writing.\u003c/p\u003e\n"],["\u003cp\u003eWriting to Google Cloud Storage differs from writing to a local disk, as it does not support modifying or appending to existing files, and requires creating new files to overwrite, impacting performance, especially with frequent modifications.\u003c/p\u003e\n"],["\u003cp\u003eFiles can be written to Google Cloud Storage from an app either at once or in a streamed manner, using \u003ccode\u003efile_put_contents\u003c/code\u003e or \u003ccode\u003efopen\u003c/code\u003e/\u003ccode\u003efwrite\u003c/code\u003e, with the stream wrapper using \u003ccode\u003egs://\u003c/code\u003e to identify the bucket or file object.\u003c/p\u003e\n"],["\u003cp\u003eWhile writing files at runtime in App Engine PHP 5 requires the Cloud Storage stream wrapper, reading static files uploaded with the app is possible using PHP filesystem functions like \u003ccode\u003efile_get_contents\u003c/code\u003e, as long as they are in an application subdirectory and the \u003ccode\u003eapp.yaml\u003c/code\u003e file is configured correctly.\u003c/p\u003e\n"]]],[],null,["# Reading and Writing 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\nIn the Google App Engine PHP 5 Standard Environment, the local filesystem that your application is deployed\nto is not writeable. This behavior ensures the security\nand scalability of your application.\n\nHowever, if your application needs to write and read files at runtime, the\nPHP 5 standard environment provides a built-in Google Cloud Storage stream wrapper\nthat allows you to use many of the standard\n[PHP filesystem functions](/appengine/docs/legacy/standard/php/googlestorage/advanced#filesystem_functions_support_on_cloud_storage)\nto read and write files.\n| **Important:** One major difference between writing to a local disk and writing to Google Cloud Storage is that Google Cloud Storage doesn't support modifying or appending to a file after you close it. To get an equivalent behavior in Google Cloud Storage, you must create a new file with the same name, which overwrites the original. Because of this, the *performance* characteristics of reading and writing files to Google Cloud Storage can be quite different from reading and writing to local disk, *especially when frequent modifications need to be made to the same file*.\n\nThere are two ways to write files to Google Cloud Storage:\n\n- Write files from your app\n - Simple file write\n - Streamed file write\n- Let the user upload files to Google Cloud Storage\n\nWriting files from your app\n---------------------------\n\nIf you write files from your app, you can write the entire file at once, or you\ncan stream the file write.\n| **Important:** For very large files, you may not be able to write directly from your app, because of the requirement for all app requests to complete within the [request timeout](/appengine/docs/legacy/standard/php/how-instances-are-managed#timeout). So, for very large files, you may need to [upload the file](/appengine/docs/legacy/standard/php/googlestorage/user_upload) directly, not write it from the app.\n\nThe App Engine stream wrapper for Cloud Storage is built in to the\nruntime, and is used when you supply a file name starting with `gs://`. The wrapper\nrequires the name of the bucket or file object to be in the form:\n\n`gs://bucket_name/desired_object_name`\n\n### Simple file write\n\nTo write data to Google Cloud Storage from your app, you use\n`file_put_contents`, using a valid cloud storage URL. For example: \n\n file_put_contents(\"gs://${my_bucket}/hello.txt\", $newFileContent);\n\nwhere `my_bucket` is a\n[properly configured Google Cloud Storage bucket](/appengine/docs/legacy/standard/php/googlestorage/setup).\n\nOr, if you want to use [stream options](/appengine/docs/legacy/standard/php/googlestorage/advanced#permissions_caching_and_metadata_options)\nto supply permissions, caching, and/or metadata options, you could write the\nfile as follows: \n\n $options = ['gs' =\u003e ['Content-Type' =\u003e 'text/plain']];\n $context = stream_context_create($options);\n file_put_contents(\"gs://${my_bucket}/hello_options.txt\", $newFileContent, 0, $context);\n\n### Streamed file write\n\nAlternatively, you could use `fopen`/`fwrite` to write data in a streaming\nfashion: \n\n $fp = fopen(\"gs://${my_bucket}/hello_stream.txt\", 'w');\n fwrite($fp, $newFileContent);\n fclose($fp);\n\nNote that when you use streaming, data will be flushed to Google Cloud Storage in smaller chunks.\nYou do not need to know the total length of the data to be written up front: it\nwill be calculated when the file resource is closed:\n| **Note:** You can also use [stream options](/appengine/docs/legacy/standard/php/googlestorage/advanced#permissions_caching_and_metadata_options) when using streaming file writes to supply permissions, caching, and/or metadata options.\n\nThese are the basic ways to write files. For special use cases and more advanced\nfile management, see the topics listed under [Where to go next](#where_to_go_next).\n\nDeleting files\n--------------\n\nIf you want to delete the file itself, use the PHP [unlink()](http://php.net/unlink) function.\n\nUser uploads\n------------\n\nFor details about this file write option, see\n[Allowing Users to Upload Files](/appengine/docs/legacy/standard/php/googlestorage/user_upload)\n\nReading files\n-------------\n\nFor information about reading files from Google Cloud Storage, see\n[Providing Public Access to Files](/appengine/docs/legacy/standard/php/googlestorage/public_access)\n\nSetup and Requirements\n----------------------\n\nYou need to activate Google Cloud Storage and create a bucket. See [Setup](/appengine/docs/legacy/standard/php/googlestorage/setup)\nfor more details.\n| **Note:** Some older App Engine applications may be able to use a [default bucket](/appengine/docs/legacy/standard/php/googlestorage/setup#useful_tricks_when_using_default_buckets) that has [free quota](/appengine/docs/quotas#Default_Gcs_Bucket).\n\nSupported PHP 5 filesystem functions\n------------------------------------\n\nMany of the commonly used PHP 5 file functions are supported,\nalong with file information and directory functions. For a complete list of\nsupported PHP functions, see [PHP 5 filesystem functions support](/appengine/docs/legacy/standard/php/googlestorage/advanced#filesystem_functions_support_on_cloud_storage).\n\nExtended features provided by Cloud Storage Tools API\n-----------------------------------------------------\n\nThe Google Cloud Storage stream wrapper lets you use PHP filesystem calls. However, there are\nextended features available that you may need for an optimal use of Google Cloud Storage. These\nextended features are provided in the\n[Cloud Storage Tools API](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.cloud_storage.CloudStorageTools):\n\nThis API provides a set of functions that support the serving of files and\nimages, along with other useful utilities. We'll cover several of these in\nthe other [topic pages](#where_to_go_next).\n\nIs there any other way to read and write files?\n-----------------------------------------------\n\nAn App Engine PHP 5 app must use the Cloud Storage stream wrapper\nto write files at runtime. However, if an app needs to *read* files, and these\nfiles are static, you can optionally read static files uploaded with your app\nusing PHP filesystem functions such as `file_get_contents`.\n\nFor example: \n\n $fileContents = file_get_contents($filePath);\n\nwhere the path specified must be a path relative to the script accessing them.\n\nYou must upload the file or files in an application subdirectory when you deploy\nyour app to App Engine, and must configure the `app.yaml` file so your\napp can access those files. For complete details, see\n[PHP 5 Application Configuration with `app.yaml`](/appengine/docs/legacy/standard/php/config/appref).\n\nIn the `app.yaml` configuration, notice that if you use a static file or directory handler\n(`static_files` or `static_dir`) you must specify\n`application_readable` set to true or your app won't be able to read the files.\nHowever, if the files are served by a `script` handler, this isn't necessary,\nbecause these files are readable by script handlers by default.\n\nWhere to go next\n----------------\n\nRead the following topics for details on using the Cloud Storage Tools API:\n\n- [Setup](/appengine/docs/legacy/standard/php/googlestorage/setup), quick setup instructions.\n- [Providing Public Access to Files](/appengine/docs/legacy/standard/php/googlestorage/public_access), shows how to enable users to download files via browser.\n- [Allowing Users to Upload Files](/appengine/docs/legacy/standard/php/googlestorage/user_upload), shows how to upload files via browser directly, bypassing your app.\n- [Working with Image Files](/appengine/docs/legacy/standard/php/googlestorage/images), shows optimal ways to manage and serve images.\n- [Advanced File Management](/appengine/docs/legacy/standard/php/googlestorage/advanced), covers the following:\n - Permissions, caching, and metadata stream options.\n - PHP filesystem function support.\n - Using PHP `include` and `require`.\n - Reading and writing custom metadata.\n - Cached file reads."]]