A self-written PHP Upload class

Source: Internet
Author: User

Main functions:
File Upload, get file name, get file size, randomly generate new file name, get file type, Image Generation thumbnail, return the thumbnail file name, return the file name generated after upload, returns the path of the uploaded file.

Class ieb_upload {
Var $ FormName; // file Domain Name
Var $ Directroy; // upload to the directory
Var $ MaxSize; // maximum upload size
Var $ CanUpload; // whether the file can be uploaded
Var $ doUpFile; // name of the uploaded file
Var $ sm_File; // The Name Of The thumbnail.
Var $ Error; // Error parameter

Function ieb_upload ($ formName = '', $ dirPath ='', $ maxSize = 2097152) // (1024*2) * 1024 = 2097152 is 2 M
{
Global $ FormName, $ Directroy, $ MaxSize, $ CanUpload, $ Error, $ doUpFile, $ sm_File;
// Initialize various parameters
$ FormName = $ formName;
$ MaxSize = $ maxSize;
$ CanUpload = true;
$ DoUpFile = '';
$ Sm_File = '';
$ Error = 0;

If ($ formName = ''){
$ CanUpload = false;
$ Error = 1;
Break;
}

If ($ dirPath = ''){
$ Directroy = $ dirPath;
} Else {
$ Directroy = $ dirPath .'/';
}
}

// Check whether the file exists
Function scanFile ()
{
Global $ FormName, $ Error, $ CanUpload;

If ($ CanUpload ){

$ Scan = is_readable ($ _ FILES [$ FormName] ['name']);

If ($ scan ){
$ Error = 2;
}

Return $ scan;
}
}


// Get the file size
Function getSize ($ format = 'B ')
{
Global $ FormName, $ Error, $ CanUpload;

If ($ CanUpload ){

If ($ _ FILES [$ FormName] ['SIZE'] = 0 ){
$ Error = 3;
$ CanUpload = false;
}

Switch ($ format ){

Related Article

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.