Finished new working uploader filename randomizer algorithm (abbr. as UFNRA).

master
YandolsZX 6 years ago
parent cc199bf1b0
commit 69ad885419
  1. 44
      upload.php

@ -1,6 +1,6 @@
<?php <?php
//Imeji Uploader Core Code -- Version 1.2b (Migrations Phase 1) //Imeji Uploader Core Code -- Version 1.3 (Uploader Filename Randomizer Algorithm Update)
$imejicoreversion = "imeji_v1.2b_S_p1"; $imejicoreversion = "imeji_v1.3_0";
$target_dir = "public/"; $target_dir = "public/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_filenameonly = basename($_FILES["fileToUpload"]["name"]); $target_filenameonly = basename($_FILES["fileToUpload"]["name"]);
@ -46,18 +46,50 @@ if ($uploadOk == 0) {
header('Location: ./failed.php'); header('Location: ./failed.php');
// if everything is ok, try to upload file // if everything is ok, try to upload file
} else { } else {
// 1.2a -- Changed some case-confusing characters such as I and O to web safe symbols. // 1.2a --- Changed some case-confusing characters such as I and O to web safe symbols.
$characters = 'abcdefghjklmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ1234567890-_!$+*'; // 1.3 ---- Removed some problematic symbol characters that can break CMS such as + and $.
$random_string_length = 12; // 1.3_0 -- Changed the filename randomizer algorithm to compensate for characters pool reduction to 62 from 64.
$characters = 'abcdefghjklmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ1234567890-_!*';
$random_string_length = 10;
$randomFilename = ''; $randomFilename = '';
for ($i = 0; $i < $random_string_length; $i++) { for ($i = 0; $i < $random_string_length; $i++) {
$randomFilename .= $characters[rand(0, strlen($characters) - 1)]; $randomFilename .= $characters[rand(0, strlen($characters) - 1)];
} }
// Day-base identifiers (Implemented in v1.3_0)
if (date('D') == 'Sun') {
$dayId = 'Q';
} else if (date('D') == 'Mon') {
$dayId = 'a';
} else if (date('D') == 'Tue') {
$dayId = 'z';
} else if (date('D') == 'Wed') {
$dayId = '2';
} else if (date('D') == 'Thu') {
$dayId = 'W';
} else if (date('D') == 'Fri') {
$dayId = 's';
} else if (date('D') == 'Sat') {
$dayId = 'x';
} else {
$dayId = '0';
}
// Hour-base identifiers (Implemented in v1.3_0)
if ((date('H') >= '00') && (date('H') <= '05')) {
$hourId = '3';
} else if ((date('H') >= '06') && (date('H') <= '11')) {
$hourId = 'E';
} else if ((date('H') >= '12') && (date('H') <= '17')) {
$hourId = 'd';
} else if ((date('H') >= '18') && (date('H') <= '23')) {
$hourId = 'C';
} else {
$hourId = 'z';
}
//$newfilename = time() . '_' . rand(1000000, 9999999) . '.' . end(explode(".",$_FILES["fileToUpload"]["name"])); --prior to v0.6b //$newfilename = time() . '_' . rand(1000000, 9999999) . '.' . end(explode(".",$_FILES["fileToUpload"]["name"])); --prior to v0.6b
//$newfilename = time() . '_' . rand(100, 999) . '_' . rand(100000000, 999999999) . '.' . end(explode(".",$_FILES["fileToUpload"]["name"])); --prior to v0.8 //$newfilename = time() . '_' . rand(100, 999) . '_' . rand(100000000, 999999999) . '.' . end(explode(".",$_FILES["fileToUpload"]["name"])); --prior to v0.8
//$newfilename = $randomFilename . '.' . end(explode(".",$_FILES["fileToUpload"]["name"]));
$newfilename = $randomFilename . '.' . end(explode(".",$_FILES["fileToUpload"]["name"])); $newfilename = $randomFilename . '.' . end(explode(".",$_FILES["fileToUpload"]["name"]));
$newtarget = $target_dir . $newfilename; $newtarget = $target_dir . $newfilename;
//if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newtarget)) { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $newtarget)) {
chmod("$newtarget", 0775); // Set read and write permissions if file chmod("$newtarget", 0775); // Set read and write permissions if file
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";

Loading…
Cancel
Save