PHP file picture upload class program _php tutorial

Source: Internet
Author: User




PHP Tutorial file picture upload class program




upx.php file
Upload operation
Require_once './libs/uploadx.php ';
$UPX = new UPLOADX ();
$upx->uploadx_form = ' swfile ';
$UPX->uploadx_save = "Upload";
$UPX->uploadx_size = "1024";
$UPX->uploadx_name = time ();
$UPX->file ();
Print_r ($upx->file);

?>
uploadx.php class file
/*

How to use:

HTML Form page
-------------------------------------------------------------------------

-------------------------------------------------------------------------


upload.php Processing page
-------------------------------------------------------------------------
Require_once './uploadx.php ';
$UPX = new UPLOADX ();
$upx->uploadx_form = ' swfile '; Form control Name (name of the form upload control)
$UPX->uploadx_save = "temp"; Save file directory (upload file to save directory can be a relative path or an absolute path)
$upx->uploadx_type = ' jpg|gif|png|swf '; Allow upload type (depending on the suffix limit upload type, each suffix with "|" Separated
$UPX->uploadx_size = "1024"; Allow upload size (in kilobytes). Example: 1024=1024KB)
$UPX->uploadx_name = time (); File name after uploading (customizable.) Example: Date ("y-m-d", Time ()))

if ($upx->file ()) {
echo "Upload successful
";
echo "name". $upx->file[' name ']. "
";
echo "path". $upx->file[' path ']. "
";
echo "Size---" $upx->file[' sizes '. "
";
echo "type". $upx->file[' type ']. "
";
echo "Time," $upx->file['.
";
echo "Results". $upx->file[' info ']. "
";

}else{
echo $upx->file[' info '];
}

-------------------------------------------------------------------------
*/
Class UPLOADX {


Public $UPLOADX _form; Form Control Name
Public $UPLOADX _save; Save file Directory
Public $UPLOADX _type; Allow upload type
Public $UPLOADX _size; Allow upload size
Public $UPLOADX _name; File name after upload

function __construct () {//initialization functions
$this->uploadx_form = ' attach ';
$this->uploadx_save = ' temp ';
$this->uploadx_type = ' jpg|gif|png|swf|flv|rar|7z|zip|doc|docx|ppt|pptx|xls|xlsx|txt|pdf|wav|mp3|wma|rm|rmvb| WMV ';
$this->uploadx_size = ' 1024 ';
$this->uploadx_info = false;
}

function Mkdirs ($path, $mode = 0777) {
$rootdir = ";
if (substr ($path, 0,1) = = '/') $rootdir = $_server[' Document_root '];
$path = $rootdir. $path;
if (!is_dir ($path)) {
$this->mkdirs (DirName ($path), $mode);
mkdir ($path, $mode);
}
return true;
}

function file () {
if (!isset ($_files[$this->uploadx_form])) {
$this->file = Array (' file ' =>false, ' info ' = ' + ' upload error!) Please check the form upload control name ['. $this->uploadx_form. '] is correct! ');
return false;
}

Switch ($_files[$this->uploadx_form][' error ') {

Case 1:
$this->file = Array (' file ' =>false, ' info ' and ' = ' specifies that the uploaded file size exceeds the server limit! ');
return false;
Break

Case 2:
$this->file = Array (' file ' =>false, ' info ' and ' = ' specifies that the uploaded file size exceeds the form limit! ');
return false;
Break

Case 3:
$this->file = Array (' file ' =>false, ' info ' = ' Only some files are uploaded, the file is incomplete! ');
return false;
Break

Case 4:
$this->file = Array (' file ' =>false, ' info ' = ' You have not chosen to upload any files! ');
return false;
}

$postfix = PathInfo ($_files[$this->uploadx_form][' name '], pathinfo_extension);
if (Stripos ($this->uploadx_type, $postfix) ===false) {
$this->file = Array (' file ' =>false, ' info ' = + ' Specifies that the uploaded file type exceeds the limit and allows the file type to be uploaded: '. $this->uploadx_type);
return false;

}

if (Round ($_files[$this->uploadx_form][' size ']/1024) > $this->uploadx_size) {
$this->file = Array (' file ' =>false, ' info ' = + ' Specifies that the uploaded file exceeds the size limit, file upload limit: '. $this->uploadx_size. ' KB ');
return false;
}

if ($this->mkdirs ($this->uploadx_save)) {
$this->uploadx_name = isset ($this->uploadx_name)? $this->uploadx_name. $postfix: $_files[$this->uploadx_form][' name '];
if (! @move_uploaded_file ($_files[$this->uploadx_form][' tmp_name '), $this->uploadx_save. ' /'. $this->uploadx_name)) {
$this->file = Array (' file ' =>false, ' info ' + ' = ' upload file ' error occurred during save, check path or directory permissions.)
return false;
}
}else{
$this->file = Array (' file ' =>false, ' info ' \ = ' Server directory does not exist, automatic directory creation failed, please check if there is permission! ');
return false;
}

@chmod ($this->uploadx_save. ' /'. $this->uploadx_name,0777);
$this->file = Array (
' File ' = True,
' Name ' = $this->uploadx_name,
' Path ' = $this->uploadx_save. ' /'. $this->uploadx_name,
' Size ' = $_files[$this->uploadx_form][' size '),
' Type ' = $postfix,
' Time ' = Time (),
' Info ' = ' Upload successful! '
);
return true;

}


}


http://www.bkjia.com/PHPjc/444792.html www.bkjia.com true http://www.bkjia.com/PHPjc/444792.html techarticle HTML head meta http-equiv=content-type content=text/html charset=utf-8/titlephp Tutorial file picture upload class program/title/head body Form E Nctype=multipart/form-data action=upx.ph ...

  • 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.