Skip to content

Commit

Permalink
v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeDream committed Aug 17, 2016
1 parent 6eed126 commit 03b40f5
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 101 deletions.
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[PHP] Uploader 0.2
[PHP] Uploader 0.3
============
PHP File Uploader is an easy to use, hi-performance File Upload Script which allows you to upload/download files to webserver

Expand All @@ -9,7 +9,7 @@ Usage
__Upload:__
~~~~ php
include('src/class.uploader.php');

$uploader = new Uploader();
$data = $uploader->upload($_FILES['files'], array(
'limit' => 10, //Maximum Limit of files. {null, Number}
Expand All @@ -19,6 +19,7 @@ $data = $uploader->upload($_FILES['files'], array(
'uploadDir' => 'uploads/', //Upload directory {String}
'title' => array('auto', 10), //New file name {null, String, Array} *please read documentation in README.md
'removeFiles' => true, //Enable file exclusion {Boolean(extra for jQuery.filer), String($_POST field name containing json data with file names)}
'replace' => false, //Replace the file if it already exists {Boolean}
'perms' => null, //Uploaded file permisions {null, Number}
'onCheck' => null, //A callback function name to be called by checking a file for errors (must return an array) | ($file) | Callback
'onError' => null, //A callback function name to be called if an error occured (must return an array) | ($errors, $file) | Callback
Expand All @@ -37,24 +38,12 @@ if($data['hasErrors']){
$errors = $data['errors'];
print_r($errors);
}

function onFilesRemoveCallback($removed_files){
foreach($removed_files as $key=>$value){
$file = 'uploads/' . $value;
if(file_exists($file)){
unlink($file);
unset($removed_files[$key]);
}
}

return $removed_files;
}
~~~~

__Download:__
~~~~ php
include('src/class.uploader.php');

$uploader = new Uploader();
$data = $uploader->upload('https://www.google.com/images/srpr/logo11w.png', array(
'uploadDir' => 'uploads/', //Upload directory {String}
Expand Down Expand Up @@ -83,13 +72,14 @@ Fully documentation of class options and features.
* __uploadDir__ Upload directory {String}
* __title__ New file name
* __null__ Uploads with original file name
* __String__ Custom file name | use: auto, name, {{random}}, {{file_name}}, {{file_size}}, {{timestamp}}, {{date}}
* __String__ Custom file name | use: auto, name, {{random}}, {{file_name}}, {{file_size}}, {{timestamp}}, {{date}}, {{extension}}, {{.extension}}
* __Array__
* __String__ Custom file name | use: auto, name, {{random}}, {{file_name}}, {{file_size}}, {{timestamp}}, {{date}}
* __String__ Custom file name | use: auto, name, {{random}}, {{file_name}}, {{file_size}}, {{timestamp}}, {{date}}, {{extension}}, {{.extension}}
* __Number__ Random name length
* __removeFiles__ Enable file exclusion
* __Boolean__ extra for plugin jQuery.filer
* __String__ $_POST field name containing json data with removed files names
* __replace__ Replace the file if it already exists {Boolean}
* __perms__ Uploaded file permisions {null, Number}
* __onCheck__ A callback function name to be called by checking a file for errors (must return an array) | ($file)
* __onError__ A callback function name to be called if an error occured (must return an array) | ($errors, $file)
Expand Down
9 changes: 5 additions & 4 deletions examples/upload.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
include('../src/class.uploader.php');

$uploader = new Uploader();
$data = $uploader->upload($_FILES['files'], array(
'limit' => 10, //Maximum Limit of files. {null, Number}
Expand All @@ -10,6 +10,7 @@
'uploadDir' => 'uploads/', //Upload directory {String}
'title' => array('auto', 10), //New file name {null, String, Array} *please read documentation in README.md
'removeFiles' => true, //Enable file exclusion {Boolean(extra for jQuery.filer), String($_POST field name containing json data with file names)}
'replace' => false, //Replace the file if it already exists {Boolean}
'perms' => null, //Uploaded file permisions {null, Number}
'onCheck' => null, //A callback function name to be called by checking a file for errors (must return an array) | ($file) | Callback
'onError' => null, //A callback function name to be called if an error occured (must return an array) | ($errors, $file) | Callback
Expand All @@ -18,7 +19,7 @@
'onComplete' => null, //A callback function name to be called when upload is complete | ($file) | Callback
'onRemove' => 'onFilesRemoveCallback' //A callback function name to be called by removing files (must return an array) | ($removed_files) | Callback
));

if($data['isComplete']){
$files = $data['data'];
print_r($files);
Expand All @@ -28,15 +29,15 @@
$errors = $data['errors'];
print_r($errors);
}

function onFilesRemoveCallback($removed_files){
foreach($removed_files as $key=>$value){
$file = '../uploads/' . $value;
if(file_exists($file)){
unlink($file);
}
}

return $removed_files;
}
?>
Loading

0 comments on commit 03b40f5

Please sign in to comment.