The uploader-class attempts to greatly reduce the amount of code required to make uploading files possible in php.
Dependencies include:
- jQuerey - Access to session functionality. (including the use of cookies)
The code required to produce an upload form is as follows:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css"/>
<?php
//First we require our uploader class
require("/uploader.php");
//Then we create a new instance of the uploader class
$upload=new \uploader\upload(__DIR__."/uploads/",array("image/png","image/jpeg"),"test1","next.php");
//finally we get the html for that segment
echo $upload->get_html_segment();
?>
When the file is uploaded to the server, using ajax, an endpoint has to be available so the file can be validated. It is recommended this php file is not hidden behind any .htaccess rules. The example code for this file is as follows:
<?php
require("/uploader.php");
//Headers cannot be sent before this point
//Simply call the handle upload function and any uploads will be automatically verified (The function will exit on it being called).
\uploader\handle_upload();
?>
A class to allow for upload of files to specified locations on the given server. Should handle all client and sever side interaction during upload of files via AJAX.This includes:
1. Generation of HTML for client. 2. The handling of JavaScript to send the file to the server. 3. To store session variables so uploads can be accepted and/or validated before being placed at the given directory.
string$dir_to_upload_to* gives a specified upload directory string[]$accepted_datatypesA list of the accepted datatypes (must be in mime format without "" wildcards) string$file_name* The file name that should be held as the name of the file upon it being uploaded string$upload_endpoint* The endpoint the upload handle should try to upload information to. number$max_size* maximum accepted size of file uploaded(in bytes)
1. File uploaded automatically overwrite other files. This is true of all defined mime types. 2. Mime-types need to be used carefully , the "*" wildcard cannot be used in any capacity. Only direct mime types can be given. 3. The php_fileinfo extention needs to be enabled.
Classes of Rizza | > | PHP Uploader class | > | Download .zip .tar.gz | > | Support forum (1) | > | Blog | > | Latest changes |
|
|
Groups | Applications | Files |
Groups |
HTTP | HTTP protocol clients, headers and cookies | View top rated classes |
PHP 5 | Classes using PHP 5 specific features | View top rated classes |
Files and Folders | Listing, accessing and manipulating files and folders | View top rated classes |
AJAX | Interact with the Web server without page reloading | View top rated classes |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Files |
File | Role | Description | ||
---|---|---|---|---|
docs (1 file) | ||||
index.php | Example | Example script | ||
next.php | Aux. | Auxiliary script | ||
README.md | Doc. | Documentation | ||
uploader.php | Class | Class source |
Download all files: uploader-class.tar.gz uploader-class.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|