Use PHP to upload files to memory

Source: Internet
Author: User
PHP usually uses {code...} to process file uploads, and names the temporary files uploaded to the server to the specified directory. Is there a way for PHP to directly write the uploaded file stream to the memory, instead of generating a temporary file on the disk first? (I am doing this because the program running loop... PHP is usually used to process file uploads.

move_uploaded_file( $file['tmp_name'], $new_file )

Name the temporary file uploaded to the server to the specified directory.

Is there a way for PHP to directly write the uploaded file stream to the memory, instead of generating a temporary file on the disk first? (I am doing this because the program running environment does not allow local disk writing)

Reply content:

PHP is usually used to process file uploads.

move_uploaded_file( $file['tmp_name'], $new_file )

Name the temporary file uploaded to the server to the specified directory.

Is there a way for PHP to directly write the uploaded file stream to the memory, instead of generating a temporary file on the disk first? (I am doing this because the program running environment does not allow local disk writing)

Change the source code and re-compile the code ..

You can specify the File Upload path by setting upload_tmp_dir in php. ini. Therefore, you only need to set this path to a memory address. For linux, you can use/dev/shm, and for windows, you can use software such as RamDisk.

Directly use the/dev/shm device, which is the memory. Half of the memory size.

tmpfs                 7.5G     0  7.5G   0% /dev/shm

$memfile = file_get_contents( $file['tmp_name'] );

$ Memfile is the file in the memory... destroy the file after php is executed...

PHP cannot be passed to the memory, which has no choice for PHP.

Http://www.qixing318.com/article/php-upload-pictures-rename-6-kinds-of-schemes.html
Six Methods for renaming uploaded images in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.