>  기사  >  백엔드 개발  >  php 多文件上传_PHP教程

php 多文件上传_PHP教程

WBOY
WBOY원래의
2016-07-20 11:07:101038검색

php 多文件上传
用PHP上传多个文件,需要对许多可能的错误检查。此脚本允许上载有多少领域设置将在HTML表格中显示的最大允许上传文件大小。在php.ini文件中还包含一个名为ini选项中upload_max_filesize拥有2米的默认值,或2兆字节。此值也考虑到检查时的错误。

这些错误是存储在数组中的信息,并要求每个文件上传信息的基础上产生的任何错误或上载成功。的形式本身就是验证,按照在DOCTYPE W3C验证器。


    /*
     *
     * @ Multiple File upload script.
     *
     * @ Can do any number of file uploads
     * @ Just set the variables below and away you go
     *
     * @ Author: Kevin Waterson
     *
     * @copywrite 2008 PHPRO.ORG
     *
     */

    error_reporting(E_ALL);
 
    /*** the upload directory ***/
    $upload_dir= './uploads';

    /*** numver of files to upload ***/
    $num_uploads = 5;

    /*** maximum filesize allowed in bytes ***/
    $max_file_size  = 51200;
 
    /*** the maximum filesize from php.ini ***/
    $ini_max = str_replace('M', '', ini_get('upload_max_filesize'));
    $upload_max = $ini_max * 1024;

    /*** a message for users ***/
    $msg = 'Please select files for uploading';

    /*** an array to hold messages ***/
    $messages = array();

    /*** check if a file has been submitted ***/
    if(isset($_FILES['userfile']['tmp_name']))
    {
        /** loop through the array of files ***/
        for($i=0; $i         {
            // check if there is a file in the array
            if(!is_uploaded_file($_FILES['userfile']['tmp_name'][$i]))
            {
                $messages[] = 'No file uploaded';
            }
            /*** check if the file is less then the max php.ini size ***/
            elseif($_FILES['userfile']['size'][$i] > $upload_max)
            {
                $messages[] = "File size exceeds $upload_max php.ini limit";
            }
            // check the file is less than the maximum file size
            elseif($_FILES['userfile']['size'][$i] > $max_file_size)
            {
                $messages[] = "File size exceeds $max_file_size limit";
            }
            else
            {
                // copy the file to the specified dir
                if(@copy($_FILES['userfile']['tmp_name'][$i],$upload_dir.'/'.$_FILES['userfile']['name'][$i]))
                {
                    /*** give praise and thanks to the php gods ***/
                    $messages[] = $_FILES['userfile']['name'][$i].' uploaded';
                }
                else
                {
                    /*** an error message ***/
                    $messages[] = 'Uploading '.$_FILES['userfile']['name'][$i].' Failed';
                }
            }
        }
    }
?>
 br /> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 


 Multiple File Upload
 

 


 
 


 


     if(sizeof($messages) != 0)
    {
        foreach($messages as $err)
        {
            echo $err.'
';
        }
    }
 ?>
 


 

 
     $num = 0;
    while($num     {
        echo '
';
        $num++;
    }
 ?>

 
 

 
 


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444986.htmlTechArticlephp 多文件上传 用PHP上传多个文件,需要对许多可能的错误检查。此脚本允许上载有多少领域设置将在HTML表格中显示的最大允许上传文件大...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.