A PHP upload class written by myself_PHP tutorial

WBOY
Release: 2016-07-13 16:58:17
Original
985 people have browsed it

Main functions:
File upload, get the file name, get the file size, randomly generate a new file name, get the file type, generate a thumbnail for the image, return the thumbnail file name, return the file name of the file generated after uploading, return the file path after uploading

class ieb_upload{
var $FormName; //File domain name
var $Directroy; //Upload to directory
var $MaxSize; //Maximum upload size
var $CanUpload; //Whether it can be uploaded
var $doUpFile; //Uploaded file name
var $sm_File; //Thumbnail name
var $Error; //Error parameter

function ieb_upload($formName='', $dirPath='', $maxSize=2097152) //(1024*2)*1024=2097152 is 2M
{
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 if the file exists
function scanFile()
{
global $FormName, $Error, $CanUpload;

if ($CanUpload){

$scan = is_readable($_FILES[$FormName]['name']);

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

return $scan;
}
}


//Get file size
function getSize($format = 'B')
{
global $FormName, $Error, $CanUpload;

if ($CanUpload){

if ($_FILES[$FormName]['size'] == 0){
$Error = 3;
$CanUpload = false;
}

switch ($format){

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631406.htmlTechArticleMain functions: File upload, get file name, get file size, randomly generate new file name, get file type, The image generates a thumbnail, returns the thumbnail file name, and returns the uploaded...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template