Last active
October 1, 2018 21:59
-
-
Save t0nic/1fbebbee79ef934402688ead16271e12 to your computer and use it in GitHub Desktop.
Modifcation of the core.php save_file () function on https://github.com/nokonoko/Uguu to clear exif data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Saving the file on the server | |
function save_file ($file, $name, $arg, $type){ | |
// Verify extension | |
$ext = pathinfo($file.$name, PATHINFO_EXTENSION); | |
$ext = strtolower($ext); | |
verify_extension($ext, $type); | |
// Clear exif data from jpeg images | |
if ($ext == '.jpg' || $ext == '.jpeg') | |
{ | |
$cleanFile = new Imagick($file); | |
$profiles = $cleanFile->getImageProfiles("icc", true); | |
$cleanFile->stripImage(); | |
$cleanFile->Clear(); | |
$cleanFile->destroy(); | |
} | |
//Generate name depending on arg | |
switch($arg){ | |
case 'random': | |
$file_name = gen_name('random', $ext); | |
while(file_exists(CONFIG_FILES_PATH.$file_name)){ | |
$file_name = gen_name('random', $ext); | |
} | |
break; | |
case 'custom_original': | |
$name = stripslashes(str_replace('/', '', $name)); | |
$name = strip_tags(preg_replace('/\s+/', '', $name)); | |
$file_name = gen_name('custom_original', $name); | |
while(file_exists(CONFIG_FILES_PATH.$file_name)){ | |
$file_name = gen_name('custom_original', $name); | |
} | |
break; | |
} | |
//Move the file to the above location with said filename | |
move_uploaded_file($file,CONFIG_FILES_PATH.$file_name); | |
//Check if html or plain text should be returned | |
if($type==='tool'){ | |
//Return url+filename to the user (plain text) | |
if(CONFIG_SUBUPLOAD_URL_ENABLED == "true"){ | |
echo CONFIG_SUBUPLOAD_URL.'/'.urlencode($file_name); | |
}else{ | |
echo CONFIG_ROOT_URL.'/files/'.urlencode($file_name); | |
} | |
exit(0); | |
}elseif($type==='normal'){ | |
//Return url+filename to the user (HTML) | |
$n=urlencode($file_name); | |
include_once(CONFIG_ROOT_PATH.'upload-done.php'); | |
exit(0); | |
} | |
} | |
#Generate a random name for the uploaded file | |
function gen_name($arg, $in){ | |
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | |
$name = ''; | |
for ($i = 0; $i < CONFIG_RANDOM_LENGTH; $i++) { | |
$name .= $chars[mt_rand(0, 60)]; | |
} | |
switch($arg){ | |
case 'random': | |
return $name.'.'.$in; | |
break; | |
case 'custom_original': | |
return $name.'_'.$in; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment