Skip to content

Commit 63dcec3

Browse files
committed
add files
0 parents  commit 63dcec3

16 files changed

+1579
-0
lines changed

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## PHPFileUploader
2+
A simple php library for uploading files.
3+
4+
#### Features
5+
* Upload single or multiple file.
6+
* Generate random name for the files.
7+
* Create a custom name for the files.
8+
* Files verification.
9+
10+
#### Installation
11+
via composer
12+
``` bash
13+
14+
```
15+
16+
#### Simple Example
17+
``` php
18+
require ('vendor/autoload.php');
19+
20+
$file = new \PhpFileUploader\Uploader('inputfilename'); // Specify the input file name.
21+
$file->path('/files/'); // Specify the files destination path.
22+
$file->upload(); // move uploaded files (You should call this method at the end).
23+
```
24+
25+
#### Generate random name
26+
You can use this method ```createRandomName()``` to generate a random name for the files.
27+
If you don't call this method the files will be uploaded with their original name.
28+
29+
**Ex:**
30+
``` php
31+
$file = new \PhpFileUploader\Uploader('inputfilename');
32+
$file->path('/files/');
33+
$file->createRandomName(); // Generates random name.
34+
$file->upload();
35+
```
36+
37+
#### Create custom name
38+
You can use this method ```createFileName()``` to create a custom name for the file.
39+
40+
**Ex:**
41+
``` php
42+
$file = new \PhpFileUploader\Uploader('inputfilename');
43+
$file->path('/files/');
44+
$file->createFileName('myCustomName'); // Create custom name.
45+
$file->upload();
46+
```
47+
48+
#### Check errors
49+
This method ```displayUploadErrors()``` will return an array with error messages.
50+
The library will verify the files to check whether the file exists, selected or has been uploaded successfully or not.
51+
52+
#### Upload multiple file
53+
* Add this attribute ```multiple="multiple"``` to the **HTML** input file to allow you select multiple file.
54+
* Make the input name as array ```name="files[]"```.
55+
* The library will process all the files and upload it. :)
56+
57+
#### Full Example with HTML form
58+
``` php
59+
require ('vendor/autoload.php');
60+
61+
if (isset($_POST['upload']))
62+
{
63+
$file = new \PhpFileUploader\Uploader('myFile'); // Specify the input file name.
64+
$file->path('/files/'); // Specify the files destination path.
65+
$file->createRandomName(); // Generate random name.
66+
$file->upload(); // move uploaded files (You should call this method at the end).
67+
68+
// Display errors as array
69+
$file->displayUploadErrors()
70+
71+
// Check if the files uploaded or not
72+
if ($file->success()) {
73+
// Success
74+
echo 'Files have been uploaded';
75+
} else {
76+
// Failed
77+
}
78+
}
79+
```
80+
``` html
81+
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="POST" enctype="multipart/form-data">
82+
<input type="file" name="myFile[]" multiple="multiple">
83+
<button type="submit" name="upload">upload</button>
84+
</form>
85+
```

composer.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "phpuploader/php-file-uploader",
3+
"description": "Verify and upload files with php.",
4+
"license": "MIT",
5+
"autoload": {
6+
"psr-4": {
7+
"PhpFileUploader\\": "src/"
8+
}
9+
},
10+
"authors": [
11+
{
12+
"name": "ahmedhassan",
13+
"email": "ahmedh12491@gmail.com"
14+
}
15+
],
16+
"require": {}
17+
}

composer.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)