PHP automatically allocates paths when uploading files ,. PHP automatically allocates paths when uploading files. This document describes how PHP automatically allocates paths when uploading files. Share it with you for your reference. The specific analysis is as follows: how to automatically allocate paths when uploading files on the website using PHP,
This example describes how to automatically allocate paths when uploading files in PHP. Share it with you for your reference. The specific analysis is as follows:
When a website uploads a file, if it is a small enterprise site, it is okay to put it in a directory. when the website is large and there are too many files uploaded, we cannot put it in the same directory, here we will talk about how to use PHP to automatically allocate paths to uploaded files.
PHP allocates a file Upload path instance
The main program snippets are as follows:
The code is as follows:
<? Php
/* Digitally allocate paths */
Function allotPath ($ id, $ extend = 'jpg '){
$ Folders = str_split (sprintf ("% 012 s", $ id), 3 );
$ Folders [3] = $ id;
Return '/'. join ('/', $ folders). '.'. $ extend;
}
/* Allocate paths by means of collection */
Function allotHashPath ($ id, $ extend = 'jpg '){
$ Folders = array_slice (str_split (md5 ($ id), 2), 0, 4 );
$ Folders [] = $ id;
Return '/'. join ('/', $ folders). '.'. $ extend;
}
Var_dump (allotPath (122333 ));
// String (23) "/000/000/122/122333 .jpg"
Var_dump (allothash path (122333 ));
// String (23) "/9c/7c/c2/cd/122333.jpg"
Here we will focus on the allocation of paths in the number mode and the allocation of paths in the miscellaneous mode. we can also allocate paths by date. if you are interested in this issue, you can do it yourself.
I hope this article will help you with php programming.
Example: describes how to automatically allocate paths when uploading files in PHP. Share it with you for your reference. The specific analysis is as follows: on the website...