Can I get downloaded files in PHP without storing them in the file system?

As far as I know, PHP stores all the downloaded files in upload_tmp_dir (or the system grandfather tmp dir if upload_tmp_dir is not installed in the php.ini file).

Then the usual way is to move this file to another location using move_uploaded_file

My question is: is there a way to get the file in a variable? Therefore, it does not need to be stored in the file system at any time?

Reasons: I do not need to clean up the files after that, and I do not need to worry about file system permissions.

+4
source share
2 answers
$contents = file_get_contents($_FILES['name']['tmp_name']); 

It is generally safe to leave the temporary file as it is, PHP will take care of deleting it at the end of the request (unless PHP fails during your script).

+2
source

Perhaps you can read the temporary file, convert it to Base64 (for example) and save it to a variable ..

0
source

Source: https://habr.com/ru/post/1380180/


All Articles