基本/upload

基本上传系统

2.0.5 2018-03-03 18:25 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:06:27 UTC


README

⬆️ 基本上传系统

如何使用

composer

composer require basic/upload

前端

<form action="upload.php" enctype="multipart/form-data" method="post">
    <input name="file" type="file">
    <button type="submit">Enviar</button>
</form>

后端 (upload.php)

<?php
require 'vendor/autoload.php';
use Basic\Upload;
$Upload=new Upload();
$exts=[
'jpg',
'png',
'gif'
];
$file=$Upload->upload('file',$exts);
if(isset($file['errors'])){
    print '<pre>';
    print_r($file['errors']);
}else{
    print 'arquivo enviado com sucesso';
}

返回的字段 ($file)

name        nome original do arquivo (string)
ext         extensão do arquivo (string)
is_image    retorna se é imagem (bool)
size        retorna o tamanho do arquivo e bytes (int)
temp        caminho temporário do arquivo (string)
errors      mensagens de erro

错误消息 ($file['errors'])

invalid_extension
invalid_size
unknown_error