Home >Backend Development >PHP Tutorial >Actual testing process of temporary storage files and recycling mechanism of $_FILES in PHP_PHP Tutorial

Actual testing process of temporary storage files and recycling mechanism of $_FILES in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:00:51776browse

I think people who have the same idea as me will handle it like this: the uploaded file is only for temporary use, there is no need to save the original file for backup, such as resize and other operations, and these later operations will appear in the second round from It is operated only when requested by the client. For example, upload first, return the uploaded temporary file path to the browser, and then operate the temporary file after the user clicks it; however, in the actual implementation, it was found that the temporary file was not used during the second round of requests. , it doesn’t exist anymore, and I ran to the temporary folder to check but couldn’t find it.

I also encountered someone asking this question in a certain Q group, and the reason was similar to my implementation idea. So, I have a question, what is the principle of uploading files?
I don’t want to look at the implementation code of PHP. I thought about it briefly. It should be a recycling mechanism: after clicking on the temporary file space, PHP itself should Maintain the recycling of this space by yourself;

So I tried to upload a very large file, which was big enough for php to run for a long time. I thought I would see it appearing in the temporary folder. Unfortunately, Unfortunately, I didn't see it until php returned: because this file exceeded the upload limit; then I used a small file upload to print out its temporary folder path and found that it was a file starting with php and ending with tmp Naming method;

I thought of a way to use while to block the process of uploading php for a certain period of time and then return. This time I saw the temporary file in the temporary folder, which was indeed named php** .tmp is named like this, as shown in the figure
Actual testing process of temporary storage files and recycling mechanism of $_FILES in PHP_PHP Tutorial
If you use the abnormal end of php by refreshing the page to stop php parsing during the running of php, then this temporary file will be retained permanently.
If php ends normally, this file will be deleted when php ends.

At the same time, I feel that this file should appear after the upload is completed: it can’t be seen from the fact that I uploaded a large file. It can be inferred from its figure;
Therefore, PHP’s temporary file maintenance method is to recycle resources as soon as PHP ends. If you want to use this file in the second round of requests, you should move it yourself and maintain the file.
In this article In this test, we did not test the timing of recycling when php include multiple nesting situations.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328046.htmlTechArticleI think people who have the same idea as me will handle it like this: The uploaded file is only for temporary use, not The original file needs to be saved for later operations such as resize, and these later operations will occur...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn