• <\/form>
    <\/body>
    <\/html>

    Upload class
    upload.class.php

    \/\/
    \/\/ +------------------------ --------------------------------------------------+
    \/\/ | File upload ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????>|\/\/ | Author: whxbb(whxbb@21cn.com)??????????????????????????????????????????????????????????-------------------------------------------------- ------------------+
    \/\/
    \/\/ $Id: upload.class.php,v 1.0 2001\/10\/14 14:06:57 whxbb Exp $
    \/\/

    $UPLOAD_CLASS_ERROR = array( 1 => 'This format file is not allowed to be uploaded',
    2 => 'Directory cannot be written',
    ? ? ? ? ? 3 = > 'File already exists',
    ???????????????????????????????????????????????????????????????????????????????????????????\" );

    \/**
    * Purpose
    * File upload
    *
    * Example
    *
    $fileArr['file'] = $file;
    $fileArr['name'] = $file_name;
    $fileArr['size'] = $file_size;
    $fileArr['type'] = $file_type;
    \/\/ File types allowed to be uploaded
    $filetypes = array('gif', 'jpg','jpge','png');
    \/\/ File upload directory
    $savepath = \"\/usr\/htdocs\/upload\/\";
    \/\/ No maximum limit 0 No limit
    $maxsize = 0;
    \/\/ Overwrite 0 not allowed 1 allowed
    $overwrite = 0;
    $upload = new upload($fileArr, $file_name, $savepath, $filetypes, $overwrite, $ maxsize);
    if (!$upload->run())
    {
    echo $upload->errmsg();
    }
    *
    * @author whxbb(whxbb@21cn.com)
    * @version 0.1
    *\/
    class upload
    {
    ????var $file;
    ????var $file_name;
    ????var $file_size;
    ????var $file_type;

    ????\/**save name*\/
    ????var $savename;
    ????\/**save path*\/
    ????var $savepath;
    ????\/**File format restrictions*\/
    ????var $fileformat = array();
    ????\/**overlay mode*\/
    ????var $overwrite = 0;
    ????\/**file maximum bytes*\/
    ????var $maxsize = 0;
    ????\/**file extension*\/
    ????var $ext;
    ????\/**Error code*\/
    ????var $errno;

    ????\/**
    * Constructor
    * @param $fileArr File information array 'file' Temporary file path and file name
    'name' Upload file name
    'size' Upload file size
    ' Upload file type
    * @param savename File save name
    * @param savepath File save path
    * @param fileformat file format restriction array
    * @param overwrite whether to overwrite 1, allow overwriting 0, prohibit overwriting
    * @param maxsize Maximum file size
    *\/
    ????function upload($fileArr, $savename, $savepath, $fileformat, $overwrite = 0, $maxsize = 0) {
    ????????$this->file = $fileArr['file'];
    ????????$this->file_name = $fileArr['name'];
    ????????$this->file_size = $fileArr['size'];
    ????????$this->file_type = $fileArr['type'];

    ????????$this->get_ext();
    ????????$this->set_savepath($savepath);
    ????????$this->set_fileformat($fileformat);
    ????????$this->set_overwrite($overwrite);
    ????????$this->set_savename($savename);
    ????????$this->set_maxsize($maxsize);
    ????}

    ????\/**Upload*\/
    ????function run()
    ????{
    ????????\/**Check file format*\/
    ????????if (!$this->validate_format())
    ????????{
    ????????????$this->errno = 1;
    ????????????return false;
    ????????}
    ????????\/**Check if directory is writable*\/
    ????????if(!@is_writable($this->savepath))
    ????????{
    ????????????$this->errno = 2;
    ????????????return false;
    ????????}
    ????????\/**If overwriting is not allowed, check if the file already exists*\/
    ????????if($this->overwrite == 0 && @file_exists($this->savepath.$this->savename))
    ????????{
    ????????????$this->errno = 3;
    ????????????return false;
    ????????}
    ????????\/**If there is a size limit, check if the file exceeds the limit*\/
    ????????if ($this->maxsize != 0 )
    ????????{
    ????????????if ($this->file_size > $this->maxsize)
    ????????????{
    ????????????????$this->errno = 5;
    ????????????????return false;
    ????????????}
    ????????}
    ????????\/**File upload*\/
    ???????if(!@copy($this->file, $this->savepath.$this->savename))
    ???????{
    ????????????$this->errno = 4;
    ????????????return false;
    ???????}
    ???????\/**Delete temporary files*\/
    ???????$this->destory();
    ???????return true;
    ????}

    ????\/**
    * File format check
    * @access protect
    *\/
    ????function validate_format()
    ????{

    ????????if (!is_array($this->fileformat))??\/\/ 沒(méi)有格式限制
    ????????????return true;
    ???????$ext = strtolower($this->ext);
    ????????reset($this->fileformat);
    ????????while(list($var, $key) = each($this->fileformat))
    ????????{
    ????????????if (strtolower($key) == $ext)
    ????????????????return true;
    ????????}
    ????????reset($this->fileformat);
    ????????return false;
    ????}

    ????\/**
    * Get file extension
    * access public
    *\/
    ????function get_ext()
    ????{
    ????????$ext = explode(\".\", $this->file_name);
    ????????$ext = $ext[count($ext) - 1];
    ????????$this->ext = $ext;
    ????}
    ????\/**
    * Set the maximum byte limit for uploaded files
    * @param $maxsize file size (bytes) 0: means no limit
    * @access public
    *\/
    ????function set_maxsize($maxsize)
    ????{
    ????????$this->maxsize = $maxsize;
    ????}

    ????\/**
    * Set coverage mode
    * @param coverage mode 1: Allow coverage 0: Disable coverage
    * @access public
    *\/
    ????function set_overwrite($overwrite)
    ????{
    ????????$this->overwrite = $overwrite;
    ????}

    ????\/**
    * Set the file format that is allowed to be uploaded
    * @param $fileformat The file extension array that is allowed to be uploaded
    * @access public
    *\/
    ????function set_fileformat($fileformat)
    ????{
    ????????$this->fileformat = $fileformat;
    ????}

    \/**
    * Set the save path
    * @param $savepath File saving path: ends with \"\/\"
    * @access public
    *\/
    function set_savepath($savepath)
    {
    $this->savepath = $savepath;
    }
    \/**
    * Set the file save name
    * @savename save name, if it is empty, the system will automatically generate a random file name
    * @access public
    *\/
    function set_savename($savename)
    {
    if ($savename == '') \/\/ If the file name is not set, a random file name is generated
    {
    srand ((double) microtime() * 1000000);
    $rnd = rand(100,999);
    $name = date('Ymdhis') + $rnd;
    $name = $name.\" .\".$this->ext;
    ???????} else {
    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????**
    * Delete file
    * @param $file The name of the file to be deleted
    * @access public
    *\/
    function del($file)
    {
    if(!@unlink($file))
    {
    $this->errno = 3;
    return false;
    }
    return true;
    }
    \/**
    * Delete temporary files
    * @access proctect
    *\/
    function destory()
    {
    $this->del ($this->file);
    }

    \/**
    * Get error message
    * @access public
    * @return error msg string or false
    *\/
    function errmsg()
    {
    global $UPLOAD_CLASS_ERROR;

    if ($this->errno == 0)
    return false;
    else
    return $UPLOAD_CLASS_ERROR[$this->errno];
    }
    }
    ? >
    \n \n \n\n
    \n


    http:\/\/www.bkjia.com\/PHPjc\/314183.html<\/p>\n

    www.bkjia.com<\/p>\n

    \ntrue<\/span>http: \/\/www.bkjia.com\/PHPjc\/314183.html<\/span>TechArticle<\/span>Usage example: upload.php ?php include_once \"upload.class.php\"; if ($Submit != ' ') { $fileArr['file'] = $file; $fileArr['name'] = $file_name; $fileArr['size'] = $file_size; $fileArr...<\/span><\/span> \n<\/span>\n<\/div>"}

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    Home Backend Development PHP Tutorial File upload class_PHP tutorial

    File upload class_PHP tutorial

    Jul 21, 2016 pm 04:10 PM
    include once php s upload use document Example kind


    使用示例:
    upload.php
    include_once "upload.class.php";
    if ($Submit != '')
    {
    ????$fileArr['file'] = $file;
    ????$fileArr['name'] = $file_name;
    ????$fileArr['size'] = $file_size;
    ????$fileArr['type'] = $file_type;
    ????/**Allowed file types to upload*/
    ????$filetypes = array('gif','jpg','jpge','png');
    ????/**File upload directory*/
    ????$savepath = "/usr/htdocs/upload/";
    ????/**No maximum limit 0 No limit*/
    ????$maxsize = 0;
    ????/**Override 0 not allowed 1 allowed*/
    ????$overwrite = 0;
    ????$upload = new upload($fileArr, $file_name, $savepath, $filetypes, $overwrite, $maxsize);
    ????if (!$upload->run())
    ????{
    ?????echo??"上傳失敗".$upload->errmsg();
    ????}
    }
    ?>


    File upload











    Upload class
    upload.class.php

    //
    // +------------------------ --------------------------------------------------+
    // | File upload ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????>|// | Author: whxbb(whxbb@21cn.com)??????????????????????????????????????????????????????????-------------------------------------------------- ------------------+
    //
    // $Id: upload.class.php,v 1.0 2001/10/14 14:06:57 whxbb Exp $
    //

    $UPLOAD_CLASS_ERROR = array( 1 => 'This format file is not allowed to be uploaded',
    2 => 'Directory cannot be written',
    ? ? ? ? ? 3 = > 'File already exists',
    ???????????????????????????????????????????????????????????????????????????????????????????" );

    /**
    * Purpose
    * File upload
    *
    * Example
    *
    $fileArr['file'] = $file;
    $fileArr['name'] = $file_name;
    $fileArr['size'] = $file_size;
    $fileArr['type'] = $file_type;
    // File types allowed to be uploaded
    $filetypes = array('gif', 'jpg','jpge','png');
    // File upload directory
    $savepath = "/usr/htdocs/upload/";
    // No maximum limit 0 No limit
    $maxsize = 0;
    // Overwrite 0 not allowed 1 allowed
    $overwrite = 0;
    $upload = new upload($fileArr, $file_name, $savepath, $filetypes, $overwrite, $ maxsize);
    if (!$upload->run())
    {
    echo $upload->errmsg();
    }
    *
    * @author whxbb(whxbb@21cn.com)
    * @version 0.1
    */
    class upload
    {
    ????var $file;
    ????var $file_name;
    ????var $file_size;
    ????var $file_type;

    ????/**save name*/
    ????var $savename;
    ????/**save path*/
    ????var $savepath;
    ????/**File format restrictions*/
    ????var $fileformat = array();
    ????/**overlay mode*/
    ????var $overwrite = 0;
    ????/**file maximum bytes*/
    ????var $maxsize = 0;
    ????/**file extension*/
    ????var $ext;
    ????/**Error code*/
    ????var $errno;

    ????/**
    * Constructor
    * @param $fileArr File information array 'file' Temporary file path and file name
    'name' Upload file name
    'size' Upload file size
    ' Upload file type
    * @param savename File save name
    * @param savepath File save path
    * @param fileformat file format restriction array
    * @param overwrite whether to overwrite 1, allow overwriting 0, prohibit overwriting
    * @param maxsize Maximum file size
    */
    ????function upload($fileArr, $savename, $savepath, $fileformat, $overwrite = 0, $maxsize = 0) {
    ????????$this->file = $fileArr['file'];
    ????????$this->file_name = $fileArr['name'];
    ????????$this->file_size = $fileArr['size'];
    ????????$this->file_type = $fileArr['type'];

    ????????$this->get_ext();
    ????????$this->set_savepath($savepath);
    ????????$this->set_fileformat($fileformat);
    ????????$this->set_overwrite($overwrite);
    ????????$this->set_savename($savename);
    ????????$this->set_maxsize($maxsize);
    ????}

    ????/**Upload*/
    ????function run()
    ????{
    ????????/**Check file format*/
    ????????if (!$this->validate_format())
    ????????{
    ????????????$this->errno = 1;
    ????????????return false;
    ????????}
    ????????/**Check if directory is writable*/
    ????????if(!@is_writable($this->savepath))
    ????????{
    ????????????$this->errno = 2;
    ????????????return false;
    ????????}
    ????????/**If overwriting is not allowed, check if the file already exists*/
    ????????if($this->overwrite == 0 && @file_exists($this->savepath.$this->savename))
    ????????{
    ????????????$this->errno = 3;
    ????????????return false;
    ????????}
    ????????/**If there is a size limit, check if the file exceeds the limit*/
    ????????if ($this->maxsize != 0 )
    ????????{
    ????????????if ($this->file_size > $this->maxsize)
    ????????????{
    ????????????????$this->errno = 5;
    ????????????????return false;
    ????????????}
    ????????}
    ????????/**File upload*/
    ???????if(!@copy($this->file, $this->savepath.$this->savename))
    ???????{
    ????????????$this->errno = 4;
    ????????????return false;
    ???????}
    ???????/**Delete temporary files*/
    ???????$this->destory();
    ???????return true;
    ????}

    ????/**
    * File format check
    * @access protect
    */
    ????function validate_format()
    ????{

    ????????if (!is_array($this->fileformat))??// 沒(méi)有格式限制
    ????????????return true;
    ???????$ext = strtolower($this->ext);
    ????????reset($this->fileformat);
    ????????while(list($var, $key) = each($this->fileformat))
    ????????{
    ????????????if (strtolower($key) == $ext)
    ????????????????return true;
    ????????}
    ????????reset($this->fileformat);
    ????????return false;
    ????}

    ????/**
    * Get file extension
    * access public
    */
    ????function get_ext()
    ????{
    ????????$ext = explode(".", $this->file_name);
    ????????$ext = $ext[count($ext) - 1];
    ????????$this->ext = $ext;
    ????}
    ????/**
    * Set the maximum byte limit for uploaded files
    * @param $maxsize file size (bytes) 0: means no limit
    * @access public
    */
    ????function set_maxsize($maxsize)
    ????{
    ????????$this->maxsize = $maxsize;
    ????}

    ????/**
    * Set coverage mode
    * @param coverage mode 1: Allow coverage 0: Disable coverage
    * @access public
    */
    ????function set_overwrite($overwrite)
    ????{
    ????????$this->overwrite = $overwrite;
    ????}

    ????/**
    * Set the file format that is allowed to be uploaded
    * @param $fileformat The file extension array that is allowed to be uploaded
    * @access public
    */
    ????function set_fileformat($fileformat)
    ????{
    ????????$this->fileformat = $fileformat;
    ????}

    /**
    * Set the save path
    * @param $savepath File saving path: ends with "/"
    * @access public
    */
    function set_savepath($savepath)
    {
    $this->savepath = $savepath;
    }
    /**
    * Set the file save name
    * @savename save name, if it is empty, the system will automatically generate a random file name
    * @access public
    */
    function set_savename($savename)
    {
    if ($savename == '') // If the file name is not set, a random file name is generated
    {
    srand ((double) microtime() * 1000000);
    $rnd = rand(100,999);
    $name = date('Ymdhis') + $rnd;
    $name = $name." .".$this->ext;
    ???????} else {
    ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????**
    * Delete file
    * @param $file The name of the file to be deleted
    * @access public
    */
    function del($file)
    {
    if(!@unlink($file))
    {
    $this->errno = 3;
    return false;
    }
    return true;
    }
    /**
    * Delete temporary files
    * @access proctect
    */
    function destory()
    {
    $this->del ($this->file);
    }

    /**
    * Get error message
    * @access public
    * @return error msg string or false
    */
    function errmsg()
    {
    global $UPLOAD_CLASS_ERROR;

    if ($this->errno == 0)
    return false;
    else
    return $UPLOAD_CLASS_ERROR[$this->errno];
    }
    }
    ? >




    http://www.bkjia.com/PHPjc/314183.html

    www.bkjia.com

    http: //www.bkjia.com/PHPjc/314183.htmlTechArticleUsage example: upload.php ?php include_once "upload.class.php"; if ($Submit != ' ') { $fileArr['file'] = $file; $fileArr['name'] = $file_name; $fileArr['size'] = $file_size; $fileArr...
    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

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to get the current session ID in PHP? How to get the current session ID in PHP? Jul 13, 2025 am 03:02 AM

    The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

    PHP get substring from a string PHP get substring from a string Jul 13, 2025 am 02:59 AM

    To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

    How do you perform unit testing for php code? How do you perform unit testing for php code? Jul 13, 2025 am 02:54 AM

    UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

    How to split a string into an array in PHP How to split a string into an array in PHP Jul 13, 2025 am 02:59 AM

    In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

    JavaScript Data Types: Primitive vs Reference JavaScript Data Types: Primitive vs Reference Jul 13, 2025 am 02:43 AM

    JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

    Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

    std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

    What is Late Static Binding in PHP? What is Late Static Binding in PHP? Jul 13, 2025 am 02:36 AM

    LateStaticBindinginPHPallowsstatic::torefertotheclassinitiallycalledatruntimeininheritancescenarios.BeforePHP5.3,self::alwaysreferencedtheclasswherethemethodwasdefined,causingChildClass::sayHello()tooutput"ParentClass".Withlatestaticbinding

    How to pass a session variable to another page in PHP? How to pass a session variable to another page in PHP? Jul 13, 2025 am 02:39 AM

    In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

    See all articles