PHP $ _FILES function uses

Reprinted from https://www.cnblogs.com/kenshinobiy/p/7783151.html

$ _FILES arguments detailed:
$ _FILES [ "file"] [ " name"] - the name of the uploaded file
$ _FILES [ "file"] [ "type"] - the type of uploaded file
$ _FILES [ "file"] [ " size "] - the upload file size, in bytes
$ _FILES [" file "] [ " tmp_name "] - the name of the temporary copy is stored in a file server
$ _FILES [" file "] [ " error "] - caused by the file upload error code

$ _FILES [ "file"] [ "error"] in [ "error"] the value of the case:
UPLOAD_ERR_OK
0: no error occurred, the file uploaded successfully
UPLOAD_ERR_INI_SIZE
1: uploaded file exceeds the php.ini upload_max_filesize (default is 2M ) option limits the value of
UPLOAD_ERR_FORM_SIZE
2: upload file size exceeds the value of the HTML form MAX_FILE_SIZE option specifies
UPLOAD_ERR_PARTIAL
3: file was only partially uploaded
UPLOAD_ERR_NO_FILE
4: no file was uploaded
5: file transfer size 0
Here we take a look the most basic file upload:

<html>
<body>
<form action=”upload-file.php” method=”post”
enctype=”multipart/form-data”>
<label for=”file”>文件名:</label>
<input type=”file” name=”file” id=”file” />
<br />
<input type=”submit” name=”submit” value=”提交” />
</form>
</body>
</html>

The HTML page below:

 

upload-file.php code is as follows:

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo “错误: ” . $_FILES["file"]["error"] . “<br />”;
  }
else
  {
  echo “文件名: ” . $_FILES["file"]["name"] . “<br />”;
  echo “类型: ” . $_FILES["file"]["type"] . “<br />”;
  echo “大小: ” . ($_FILES["file"]["size"] / 1024) . ” Kb<br />”;
  echo “存储位置: ” . $_FILES["file"]["tmp_name"];
  }
?>

We just upload a word file to see how to deal with the results:

File name: css.doc
Type: application / msword
Size: 81.5 Kb
storage location: C: \ WINDOWS \ temp \ php7D.tmp

You can see, this file is saved to C: \ WINDOWS \ temp \ Temp folder, you might want to see the existence of this file in this directory, but the result is:! Why not? Because php After you perform this script, it generated files and delete, so even further processing after upload. Also Incidentally, in the windows, php generated temporary files such as php7D.tmp is regular, that is to say the next time through the form to upload the file should look like this: php7E.tmp
file upload in order to save us, to use move_uploaded_file function. In your upload-file.php create a file upload folder same directory. The following look at the example above:

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo “错误: ” . $_FILES["file"]["error"] . “<br />”;
  }
else
  {
  echo “文件名: ” . $_FILES["file"]["name"] . “<br />”;
  echo “类型: ” . $_FILES["file"]["type"] . “<br />”;
  echo “大小: ” . ($_FILES["file"]["size"] / 1024) . ” Kb<br />”; 
  }
 if (file_exists(”upload/” . $_FILES["file"]["name"]))
    {
      echo $_FILES["file"]["name"] . ” 文件已经存在. “;
    }
else
    {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      “upload/” . $_FILES["file"]["name"]);
      echo "file has been stored to:" "Upload /" $ _FILES [ "File"] [ "name"];..
    }

 

?>

Let's look at the results:

File name: css.doc
Type: application / msword
Size: 81.5 Kb
file has been stored to: upload / css.doc

After this step of the process, in place (upload) we specify that we can get the file upload. Here, the basic file upload is over.

 

 

 

$ _FILES arguments detailed:
$ _FILES [ "file"] [ " name"] - the name of the uploaded file
$ _FILES [ "file"] [ "type"] - the type of uploaded file
$ _FILES [ "file"] [ " size "] - the upload file size, in bytes
$ _FILES [" file "] [ " tmp_name "] - the name of the temporary copy is stored in a file server
$ _FILES [" file "] [ " error "] - caused by the file upload error code

$ _FILES [ "file"] [ "error"] in [ "error"] the value of the case:
UPLOAD_ERR_OK
0: no error occurred, the file uploaded successfully
UPLOAD_ERR_INI_SIZE
1: uploaded file exceeds the php.ini upload_max_filesize (default is 2M ) option limits the value of
UPLOAD_ERR_FORM_SIZE
2: upload file size exceeds the value of the HTML form MAX_FILE_SIZE option specifies
UPLOAD_ERR_PARTIAL
3: file was only partially uploaded
UPLOAD_ERR_NO_FILE
4: no file was uploaded
5: file transfer size 0
Here we take a look the most basic file upload:

<html>
<body>
<form action=”upload-file.php” method=”post”
enctype=”multipart/form-data”>
<label for=”file”>文件名:</label>
<input type=”file” name=”file” id=”file” />
<br />
<input type=”submit” name=”submit” value=”提交” />
</form>
</body>
</html>

The HTML page below:

 

upload-file.php code is as follows:

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo “错误: ” . $_FILES["file"]["error"] . “<br />”;
  }
else
  {
  echo “文件名: ” . $_FILES["file"]["name"] . “<br />”;
  echo “类型: ” . $_FILES["file"]["type"] . “<br />”;
  echo “大小: ” . ($_FILES["file"]["size"] / 1024) . ” Kb<br />”;
  echo “存储位置: ” . $_FILES["file"]["tmp_name"];
  }
?>

We just upload a word file to see how to deal with the results:

File name: css.doc
Type: application / msword
Size: 81.5 Kb
storage location: C: \ WINDOWS \ temp \ php7D.tmp

You can see, this file is saved to C: \ WINDOWS \ temp \ Temp folder, you might want to see the existence of this file in this directory, but the result is:! Why not? Because php After you perform this script, it generated files and delete, so even further processing after upload. Also Incidentally, in the windows, php generated temporary files such as php7D.tmp is regular, that is to say the next time through the form to upload the file should look like this: php7E.tmp
file upload in order to save us, to use move_uploaded_file function. In your upload-file.php create a file upload folder same directory. The following look at the example above:

<?php
if ($_FILES["file"]["error"] > 0)
  {
  echo “错误: ” . $_FILES["file"]["error"] . “<br />”;
  }
else
  {
  echo “文件名: ” . $_FILES["file"]["name"] . “<br />”;
  echo “类型: ” . $_FILES["file"]["type"] . “<br />”;
  echo “大小: ” . ($_FILES["file"]["size"] / 1024) . ” Kb<br />”; 
  }
 if (file_exists(”upload/” . $_FILES["file"]["name"]))
    {
      echo $_FILES["file"]["name"] . ” 文件已经存在. “;
    }
else
    {
      move_uploaded_file($_FILES["file"]["tmp_name "],       ;echo" file has been stored to: upload / file "] ["
      ." $ _FILES [ "" Upload / File "] [" name "]);

    }

 

?>

Let's look at the results:

File name: css.doc
Type: application / msword
Size: 81.5 Kb
file has been stored to: upload / css.doc

After this step of the process, in place (upload) we specify that we can get the file upload. Here, the basic file upload is over.

 

 

 

Guess you like

Origin www.cnblogs.com/summerGraden/p/12028765.html