{"id":4071,"date":"2024-03-13T07:53:25","date_gmt":"2024-03-13T07:53:25","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/"},"modified":"2025-07-31T01:14:33","modified_gmt":"2025-07-31T01:14:33","slug":"what-is-the-usage-of-the-php-_files-function","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/","title":{"rendered":"PHP $_FILES: File Upload Guide"},"content":{"rendered":"<p>$_FILES is a superglobal variable in PHP used to handle files uploaded via the POST method. It contains an associative array with information about the uploaded file, such as the file name, file type, and the temporary file path. Using $_FILES makes it easy to access information about uploaded files and make the necessary adjustments.<\/p>\n<p>The basic steps for using $_FILES are as follows:<\/p>\n<ol>\n<li>Use the input tag in HTML forms and set the type attribute to file to specify the form field for file upload.<\/li>\n<li>In a PHP script, information about an uploaded file can be obtained through the $_FILES superglobal variable.<\/li>\n<li>Process uploaded files, such as moving them to a specified directory or renaming them.<\/li>\n<\/ol>\n<p>For example, here is a simple code example for uploading files:<\/p>\n<pre class=\"post-pre\"><code>&lt;form action=<span class=\"hljs-string\">\"upload.php\"<\/span> method=<span class=\"hljs-string\">\"post\"<\/span> enctype=<span class=\"hljs-string\">\"multipart\/form-data\"<\/span>&gt;\r\n    &lt;input type=<span class=\"hljs-string\">\"file\"<\/span> name=<span class=\"hljs-string\">\"file\"<\/span>&gt;\r\n    &lt;input type=<span class=\"hljs-string\">\"submit\"<\/span> value=<span class=\"hljs-string\">\"\u4e0a\u4f20\u6587\u4ef6\"<\/span>&gt;\r\n&lt;\/form&gt;\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta\">&lt;?php<\/span>\r\n<span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-variable\">$_FILES<\/span>[<span class=\"hljs-string\">'file'<\/span>][<span class=\"hljs-string\">'error'<\/span>] === UPLOAD_ERR_OK) {\r\n    <span class=\"hljs-variable\">$uploadDir<\/span> = <span class=\"hljs-string\">'uploads\/'<\/span>;\r\n    <span class=\"hljs-variable\">$uploadFile<\/span> = <span class=\"hljs-variable\">$uploadDir<\/span> . <span class=\"hljs-title function_ invoke__\">basename<\/span>(<span class=\"hljs-variable\">$_FILES<\/span>[<span class=\"hljs-string\">'file'<\/span>][<span class=\"hljs-string\">'name'<\/span>]);\r\n    \r\n    <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-title function_ invoke__\">move_uploaded_file<\/span>(<span class=\"hljs-variable\">$_FILES<\/span>[<span class=\"hljs-string\">'file'<\/span>][<span class=\"hljs-string\">'tmp_name'<\/span>], <span class=\"hljs-variable\">$uploadFile<\/span>)) {\r\n        <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">'\u6587\u4ef6\u4e0a\u4f20\u6210\u529f\uff01'<\/span>;\r\n    } <span class=\"hljs-keyword\">else<\/span> {\r\n        <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">'\u6587\u4ef6\u4e0a\u4f20\u5931\u8d25\uff01'<\/span>;\r\n    }\r\n}\r\n<span class=\"hljs-meta\">?&gt;<\/span>\r\n<\/code><\/pre>\n<p>In the example above, once the user uploads a file, the PHP script will move the file to the designated &#8216;uploads&#8217; directory and display a corresponding message. Using the $_FILES variable, we can easily manage user-uploaded files.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>$_FILES is a superglobal variable in PHP used to handle files uploaded via the POST method. It contains an associative array with information about the uploaded file, such as the file name, file type, and the temporary file path. Using $_FILES makes it easy to access information about uploaded files and make the necessary adjustments. [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[2891,3214,3215,891,326],"class_list":["post-4071","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-file-upload","tag-php-_files","tag-php-forms","tag-php-tutorial","tag-web-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP $_FILES: File Upload Guide - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Master PHP $_FILES for secure file uploads. Learn to handle files with examples and best practices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP $_FILES: File Upload Guide\" \/>\n<meta property=\"og:description\" content=\"Master PHP $_FILES for secure file uploads. Learn to handle files with examples and best practices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-13T07:53:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T01:14:33+00:00\" \/>\n<meta name=\"author\" content=\"Emily Johnson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Emily Johnson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/\"},\"author\":{\"name\":\"Emily Johnson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378\"},\"headline\":\"PHP $_FILES: File Upload Guide\",\"datePublished\":\"2024-03-13T07:53:25+00:00\",\"dateModified\":\"2025-07-31T01:14:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/\"},\"wordCount\":170,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"File Upload\",\"PHP $_FILES\",\"PHP forms\",\"php tutorial\",\"web development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/\",\"name\":\"PHP $_FILES: File Upload Guide - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-13T07:53:25+00:00\",\"dateModified\":\"2025-07-31T01:14:33+00:00\",\"description\":\"Master PHP $_FILES for secure file uploads. Learn to handle files with examples and best practices.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP $_FILES: File Upload Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378\",\"name\":\"Emily Johnson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g\",\"caption\":\"Emily Johnson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/emilyjohnson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PHP $_FILES: File Upload Guide - Blog - Silicon Cloud","description":"Master PHP $_FILES for secure file uploads. Learn to handle files with examples and best practices.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/","og_locale":"en_US","og_type":"article","og_title":"PHP $_FILES: File Upload Guide","og_description":"Master PHP $_FILES for secure file uploads. Learn to handle files with examples and best practices.","og_url":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-13T07:53:25+00:00","article_modified_time":"2025-07-31T01:14:33+00:00","author":"Emily Johnson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Emily Johnson","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/"},"author":{"name":"Emily Johnson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378"},"headline":"PHP $_FILES: File Upload Guide","datePublished":"2024-03-13T07:53:25+00:00","dateModified":"2025-07-31T01:14:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/"},"wordCount":170,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["File Upload","PHP $_FILES","PHP forms","php tutorial","web development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/","url":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/","name":"PHP $_FILES: File Upload Guide - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-13T07:53:25+00:00","dateModified":"2025-07-31T01:14:33+00:00","description":"Master PHP $_FILES for secure file uploads. Learn to handle files with examples and best practices.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/what-is-the-usage-of-the-php-_files-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP $_FILES: File Upload Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378","name":"Emily Johnson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g","caption":"Emily Johnson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/emilyjohnson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/4071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=4071"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/4071\/revisions"}],"predecessor-version":[{"id":148733,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/4071\/revisions\/148733"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=4071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=4071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=4071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}