1. Go to this page and download the library: Download joshmvc/filehandler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joshmvc / filehandler example snippets
use JoshMVC\Libs\FileHandler as FileHandler;
FileHandler::upload_image($_FILES["img_upload"], "myfiles/images/"); // Saves file as random name and uses the file's extension.
// OR
FileHandler::upload_image($_FILES["img_upload"], "myfiles/images/", "user1.jpg"); // Specify file name
// OR
FileHandler::upload_image($_FILES["img_upload"], "myfiles/images/", "user1.jpg", 2097152); // Specify file size limit
// OR - to add size limit without specifying name, use empty string for the third parameter:
FileHandler::upload_image($_FILES["img_upload"], "myfiles/images/", "", 2097152); // Specify file size limit
FileHandler::upload_video($_FILES["vid_upload"], "myfiles/videos/"); // Saves file as random name and uses the file's extension.
// OR
FileHandler::upload_video($_FILES["vid_upload"], "myfiles/videos/", "video1.mp4"); // Specify file name
// OR
FileHandler::upload_video($_FILES["vid_upload"], "myfiles/videos/", "video1.mp4", 2097152); // Specify file size limit
// OR - to add size limit without specifying name, use empty string for the third parameter:
FileHandler::upload_video($_FILES["vid_upload"], "myfiles/videos/", "", 2097152); // Specify file size limit
FileHandler::upload_audio($_FILES["aud_upload"], "myfiles/audio/"); // Saves file as random name and uses the file's extension.
// OR
FileHandler::upload_audio($_FILES["aud_upload"], "myfiles/audio/", "audio1.mp3"); // Specify file name
// OR
FileHandler::upload_audio($_FILES["aud_upload"], "myfiles/audio/", "audio1.mp3", 2097152); // Specify file size limit
// OR - to add size limit without specifying name, use empty string for the third parameter:
FileHandler::upload_audio($_FILES["aud_upload"], "myfiles/audio/", "", 2097152); // Specify file size limit
FileHandler::upload_document($_FILES["doc_upload"], "myfiles/docs/"); // Saves file as random name and uses the file's extension.
// OR
FileHandler::upload_document($_FILES["doc_upload"], "myfiles/docs/", "DOC_123232.pdf"); // Specify file name
// OR
FileHandler::upload_document($_FILES["doc_upload"], "myfiles/docs/", "DOC_123232.pdf", 2097152); // Specify file size limit
// OR - to add size limit without specifying name, use empty string for the third parameter:
FileHandler::upload_document($_FILES["doc_upload"], "myfiles/docs/", "", 2097152); // Specify file size limit
FileHandler::upload_compressed($_FILES["archive_upload"], "myfiles/compressed/"); // Saves file as random name and uses the file's extension.
// OR
FileHandler::upload_compressed($_FILES["archive_upload"], "myfiles/compressed/", "my_archive.rar"); // Specify file name
// OR
FileHandler::upload_compressed($_FILES["archive_upload"], "myfiles/compressed/", "my_archive.rar", 2097152); // Specify file size limit
// OR - to add size limit without specifying name, use empty string for the third parameter:
FileHandler::upload_compressed($_FILES["archive_upload"], "myfiles/compressed/", "", 2097152); // Specify file size limit