简体   繁体   中英

Uploading files to different disks/directories on server with PHP

I have a server with 2 disks. I want to upload files with PHP and let PHP dynamically choose a upload_tmp_dir directory on a disk where the file will be uploaded, either based on disk space or randomly, to reduce amount of IO per disk.

For example: if 5 file uploads are happening at the same time, PHP choose disk1 for upload 1 and 2, and disk2 for upload 3, 4, 5. Is that possible?

As I understand it: during upload, the file gets temporarily stored in the upload_tmp_dir directory. And after upload, file can be transferred to some other directory with move_uploaded_file .

But I want to let PHP first to check disk space of both disks, compare, and then proceed with uploading the file into the chosen disk - or choose a disk randomly. Is that possible? I have not seen PHP solutions like this.. But i want to keep disk IO to a minimum and utilize my disks as much as possible.

  1. You can use disk_free_space to check available disk space.
  2. Once you compare based on path from 1), you already know which disk has more spaces
  3. Based on that, you can use ini_set("upload_tmp_dir", path) to store tmp file.
  4. then you can use move_uploaded_file to store the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM