litto/

uploader

PHP应用程序中的文件上传

v1.0 2022-02-07 05:19 UTC

This package is auto-updated.

Last update: 2024-09-07 10:39:44 UTC


README

PHP中文件上传类

##如何安装?

使用Composer安装或直接从GitHub代码下载。您可以通过以下命令使用Composer安装:

composer require litto/uploader:v1.0

它是如何工作的?

当表单中提交文件时,在save函数中调用如下:

       $absDirName =   dirname(dirname(__FILE__)).'/uploads';  // uploads folder where you are storing files
        $uploader   =   new Uploader($absDirName.'/');  //Initilize Class passing the uploader path
        $uploader->setExtensions(array('jpg','jpeg','png','gif')); // Restrict the Formats valid for thsi file upload
        $uploader->setSequence('page'); // You can set name sequence or you can pass the slug varibale for making seo friendly
        $uploader->setMaxSize(2); // Set size of the Uploader file in MB
        if($uploader->uploadFile("txtFile")){  // Class is uplaoding file where our file field name is txtFile
            /*
             * File uploader successfully , now store to Db
            */
            $image      =   $uploader->getUploadName(); //getting uploaded file name
           // You can store  the file in your database
        }