ThinkPHP3.1 multifile Upload path and name

Source: Internet
Author: User
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.


Reply to discussion (solution)

After the upload class is instantiated, you can set some Upload attributes (parameters). the supported attributes include the maximum file size uploaded by the maxSize file (in bytes) the default value is-1. the storage path of the savePath file is unlimited. if it is left blank, the storage rule of the saveRule uploaded file will be taken from the path defined by the UPLOAD_PATH constant. it must be a function name without any parameters, for example, it can be time or uniqid com_create_guid, but the generated file name must be unique. by default, it is the hash verification method of the uniqidhashType uploaded File. the default value is md5_fileautoCheck. whether to automatically detect attachments, by default, the system automatically checks whether a file with the same name in uploadReplace overwrites the suffix of the file that allowExts allows to upload (leave blank is not limited) and uses array settings, the default value is the empty array allowTypes. the default value is the file type that can be uploaded. If this parameter is set using an array, the default value is whether the empty array thumb needs to perform thumbnail processing on image files, the default value is the maximum width of the falsethumbMaxWidth thumbnail. multiple values use commas to separate the maximum height of the thumbMaxHeight thumbnail. multiple file prefixes use commas to separate the thumbPrefix thumbnails. the default value is the suffix of the thumb_thumbSuffix thumbnail, the default value is the storage path of the empty thumbPath thumbnail. if it is left empty, the thumbFile in the file upload directory itself specifies the name of the thumbnail file thumbRemoveOrigin. after the thumbnail is generated, whether to delete the original image autoSub and use the subdirectory to save the subType, the default value is hash. you can set it to hash or datedateFormat when the sub-directory mode is date. you can specify the storage level of the hashLevel sub-directory of the date format. by default, you can directly set the attributes above one level.

Http://doc.thinkphp1.cn/manual

Multi-file path? You may need to rewrite the Upload class yourself.

After the upload class is instantiated, you can set some Upload attributes (parameters). the supported attributes include the maximum file size uploaded by the maxSize file (in bytes) the default value is-1. the storage path of the savePath file is unlimited. if it is left blank, the storage rule of the saveRule uploaded file will be taken from the path defined by the UPLOAD_PATH constant. it must be a function name without any parameters, for example, it can be time or uniqid com_create_guid, but the generated file name must be unique. by default, it is the hash verification method of the uniqidhashType uploaded File. the default value is md5_fileautoCheck. whether to automatically detect attachments, by default, the system automatically checks whether a file with the same name in uploadReplace overwrites the suffix of the file that allowExts allows to upload (leave blank is not limited) and uses array settings, the default value is the empty array allowTypes. the default value is the file type that can be uploaded. If this parameter is set using an array, the default value is whether the empty array thumb needs to perform thumbnail processing on image files, the default value is the maximum width of the falsethumbMaxWidth thumbnail. multiple values use commas to separate the maximum height of the thumbMaxHeight thumbnail. multiple file prefixes use commas to separate the thumbPrefix thumbnails. the default value is the suffix of the thumb_thumbSuffix thumbnail, the default value is the storage path of the empty thumbPath thumbnail. if it is left empty, the thumbFile in the file upload directory itself specifies the name of the thumbnail file thumbRemoveOrigin. after the thumbnail is generated, whether to delete the original image autoSub and use the subdirectory to save the subType, the default value is hash. you can set it to hash or datedateFormat when the sub-directory mode is date. you can specify the storage level of the hashLevel sub-directory of the date format. by default, you can directly set the attributes above one level.

$ Co ['saverule'] = date ('ymdhis ', time ()). '_'. mt_rand (); after using this set name, only one or more uploads can be uploaded. a message is displayed, indicating that the file already exists.

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 ';

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 ';

$ Co ['saverule'] = 'My _ filename'; in this way, he directly regards this as a string and changes it to the name. $ co ['saverule'] = my_filename (); I changed it so that I could not define this method.
Another question is, if no file is uploaded, He prompts that the file must be uploaded.

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 ';

This framework is the first time for new users to use,

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 ';

Didn't you define a function?
Can't you see it?

Didn't you define a function?
Can't you see it?

It doesn't mean that my function has put an error. sometimes I don't upload files when submitting the function, but he will prompt that the file has not been uploaded. how can I set it to ignore.

I don't know. I never used it.

It has already been made. it uses saveRule. it cannot work with either savename or saveName.

Continue the discussion and paste it tomorrow

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.