ThinkPHP3.1 multifile Upload path and name import (ORG. net. uploadFile); $ co & nbsp; array (); $ co [maxSize] & nbsp; 3145728; $ co [saveRule] & nbsp; date (ymdHis, time ()). _. mt_rand ThinkPHP3.1 multifile Upload path and name
Import ('org. Net. uploadfile ');
$ Co = array ();
$ Co ['maxsize'] = 3145728;
$ Co ['saverule'] = date ('ymdhis ', time ().' _ '. mt_rand ();
$ Co ['allowexts'] = array ('jpg ', 'GIF', 'PNG', 'jpeg ');
$ Co ['savepath'] = './Public/image/home/news /';
$ Upload = new UploadFile ($ co); // instantiate the upload class
If (! $ Upload-> upload () {// upload error message
$ This-> error ($ upload-> getErrorMsg ());
} Else {// the uploaded file is successfully obtained.
$ Info = $ upload-> getUploadFileInfo ();
}
In this way, when multiple files are uploaded, the file already exists and the name is repeated. And how to separate the two files and store them in different paths.
------ Solution --------------------
After the upload class is instantiated, you can set some Upload attributes (parameters). the supported attributes include:
The maximum size (in bytes) of the maxSize file uploaded is-1 by default.
SavePath file storage path. if left blank, the path defined by the constant UPLOAD_PATH will be used.
The saveRule Upload file storage rule must be a function name without any parameters, such as time and uniqid com_create_guid. However, the generated file name must be unique and the default value is uniqid.
HashType: specifies the hash verification method for uploading files. the default value is md5_file.
AutoCheck: whether to automatically detect attachments. the default value is automatic check.
Whether an uploadReplace file with the same name is overwritten
AllowExts allows the suffix of files to be uploaded (leave blank is not limited). It is set using arrays, and the default value is an empty array.
The file type that allowTypes allows to upload (leave blank is not limited). use array settings. the default value is an empty array.
Whether thumb needs to process thumbnails of image files. the default value is false.
The maximum width of the thumbMaxWidth thumbnail. multiple values are separated by commas (,).
The maximum height of the thumbMaxHeight thumbnail. multiple values are separated by commas (,).
The file prefix of the thumbPrefix thumbnail. the default value is thumb _
The file suffix of the thumbSuffix thumbnail. the default value is null.
The storage path of the thumbPath thumbnail. if it is left empty, the file upload directory itself is used.
ThumbFile specifies the thumbnail file name
Whether to delete the source image after the thumbnail is generated by thumbRemoveOrigin
Does autoSub use subdirectories to save uploaded files?
SubType sub-directory creation method. the default value is hash, which can be set to hash or date.
Specify the date format when the dateFormat subdirectory is set to date.
The level that the hashLevel sub-directory stores. the default level is one layer.
You can directly set the above attributes.
------ Solution --------------------
Http://doc.thinkphp1.cn/manual
Multi-file path? You may need to rewrite the Upload class yourself.
------ Solution --------------------
The saveRule Upload file storage rule must be a function name without any parameters
Apparently, your $ co ['saverule'] = date ('ymdhis ', time ().' _ '. mt_rand (); does not meet this requirement.
You can define a function, such
function my_filename() {
return date('ymdHis',time()).'_'.mt_rand();
}
Then
$ Co ['saverule'] = 'My _ filename ';