npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flex-element-upload

v1.0.6

Published

'Flex Element Upload is a simple and functional file upload library.

Downloads

8

Readme

Flex Element Upload

Flex Element Upload is a simple and useful npm package that helps you upload files in your projects.

  • With axios embedded in it, it uploads the files to the folder you specify by simply specifying the url (for example /uplaod.php).
  • You can set limits for file types, pixels and size.
  • Displays information of selected files.
  • You can set an upload limit for multiple uploads.
  • Can preview on first page load
  • Expects all react dependencies from the project (except axios)

Building Features

API->(POST)

If you set api -> ssr:true, it will wait for a url to meet the files in the background. In this example, processing will be done with an upload.php file in the background.

 api={{
    ssr: true,
    url: "http://localhost/upload.php",
 }}

Example of a PHP script for api post ### API->(POST)

<?php
Header("Access-Control-Allow-Origin: *");
Header("Access-Control-Allow-Headers: Content-Type");
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Credentials; true');
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["flx_file"])) {
    $uploadDir = "./upload/";
    $uploadedFile = $_FILES["flx_file"];

The name flx_file here expects the installer to provide the file. That's why you need to name it this way. The folder location is your choice.

    if ($uploadedFile["error"] == UPLOAD_ERR_OK) {
        $fileName = basename($uploadedFile["name"]);
        $fileExtension = pathinfo($fileName, PATHINFO_EXTENSION);
        $newFileName = uniqid() . "." . $fileExtension;
        $uploadPath = $uploadDir . $newFileName;
        if (move_uploaded_file($uploadedFile["tmp_name"], $uploadPath)) {
            echo json_encode(["status" => true, "file" => $newFileName]);
        } else {
            echo "Error.";
        }
    } else {
        echo "Error: " . $uploadedFile["error"];
    }
} else {
    echo "Error Send.";
}
?>

RESPONSE : OBJECT OR ARRAY

Response returns an object or an array depending on the loading selection

Appearance

response={(e) => { console.log(e) }}

Output {OBJECT}

{image: '65dbcbec246a0.png', size: '21.78KB', type: 'PNG', pixel: '120X120'}

Output [ARRAY]

[
{image: '65dbcbec246a0.png', size: '21.78KB', type: 'PNG', pixel: '120X120'}
{image: '65dbcbec2b0f3.png', size: '25.19KB', type: 'PNG', pixel: '120X120'}
{image: '65dbcbec301de.png', size: '23.05KB', type: 'PNG', pixel: '120X120'}
{image: '65dbcbec34e7b.png', size: '20.21KB', type: 'PNG', pixel: '120X120'}
]

PLACEHOLDER : OBJECT

You can pass icon, text and button text in Placeholder

 placeholder={{
     icon:any
     text: string,
     button: string
 }}

SELECTED : OBJECT OR ARRAY

Allows you to view selected, uploaded files again. There are 2 types of input methods: Object (Single upload) and Array (Multiple upload). The output of the files gives you image, size, type and pixel, if you keep them in the database, you can forward them to the next viewing. If these values are not available, you can leave them blank.

Object (Single Uplaod)

 selected={
     {image: 'http://localhost/upload/65dbabcbe2694.png', size: '23.05KB', type: 'png', pixel: '120X120' }
 }

ARRAY (Multiple Uplaod)

 selected={[
    {image: 'http://localhost/upload/65dbcbec246a0.png', size: '21.78KB', type: 'PNG', pixel: '120X120'}
    {image: 'http://localhost/upload/65dbcbec2b0f3.png', size: '25.19KB', type: 'PNG', pixel: '120X120'}
    {image: 'http://localhost/upload/65dbcbec301de.png', size: '23.05KB', type: 'PNG', pixel: '120X120'}
    {image: 'http://localhost/upload/65dbcbec34e7b.png', size: '20.21KB', type: 'PNG', pixel: '120X120'}
 ]}

SETTINGS : OBJECT

Settings allows you to turn some basic features on/off or set certain limitations.

settings={{
    imageInfo:    boolean   ->    true,
    imagepreview: boolean   ->    true,
    imageType:    array     ->    ["image/png", "image/webp", "image/webp"],
    imageSize:    string    ->    "2MB",
    imagePixel:   string    ->    "1080X1080",
    limit:        number    ->    5,
 }}

imageInfo

Show information after Image Selection?

imagepreview

Should the images be shown larger? (works if imageInfo is on)

imageType

What images can the user upload? ["image/png", "image/webp", "image/webp"]

imageSize

How many MB/KB files can the user upload?

imagePixel

How many pixels width/height should the user be able to upload files?

limit

How many files can the user upload in multiple selection?

Compilation

Both module structures were used with ESM (ES Modules) and CJS (AMD Require.JS — Async) compilation

Installation

npm install flex-element-upload
import { Uplaod } from "flex-element-upload";

Single Upload

 <Upload
    single
    selected={{
        image: 'http://localhost/upload/65dbabcbe2694.png', 
        size: '23.05KB', 
        type: 'png', 
        pixel: '120X120' 
    }}
    api={{
        ssr: true,
        url: "http://localhost/upload.php",
    }}
    response={(e) => { console.log(e) }}
    placeholder={{
        text: "Select Image",
        button: "Upload Files"
    }}
    settings={{
        imageInfo: true,
        imagepreview: true,
        imageType: ["image/png"],
        imageSize: "2MB",
        imagePixel: "1080X1080",
    }}
 />

Multiple Upload

 <Upload
    multiple
     selected={[
        {image: 'http://localhost/upload/65dbcbec246a0.png', size: '21.78KB', type: 'PNG', pixel: '120X120'},
        {image: 'http://localhost/upload/65dbcbec2b0f3.png', size: '25.19KB', type: 'PNG', pixel: '120X120'},
        {image: 'http://localhost/upload/65dbcbec301de.png', size: '23.05KB', type: 'PNG', pixel: '120X120'},
        {image: 'http://localhost/upload/65dbcbec34e7b.png', size: '20.21KB', type: 'PNG', pixel: '120X120'}
    ]}
    api={{
        ssr: true,
        url: "http://localhost/upload.php",
    }}
    response={(e) => { console.log(e) }}
    placeholder={{
        text: "Select Image",
        button: "Upload Files"
    }}
    settings={{
        imageInfo: true,
        imagepreview: true,
        imageType: ["image/png"],
        imageSize: "2MB",
        imagePixel: "1080X1080",
        limit: 5
    }}
 />

Other

The greatest legacy is the works you will leave to humanity.

I develop projects to help people. I'm trying to implement many ideas like this. You can email your support and/or requests regarding the development phase here. If you encounter errors, I will try to help. Email: [email protected]