Uploading Files
Posted 29 October 2012 - 15:00 PM
Is possible encrypt using SHA1 a upload file. Help me with this problem, I need create a form with upload file, but upload file must be encrypted in SHA1.
Thanks.
Posted 29 October 2012 - 18:45 PM
I think that you should change this code:
grocery_crud.php str. 4529
private function trim_file_name($name, $type) {
// Remove path information and dots around the filename, to prevent uploading
// into different directories or replacing hidden system files.
// Also remove control characters and spaces (\x00..\x20) around the filename:
$file_name = trim(basename(stripslashes($name)), ".\x00..\x20");
// Add missing file extension for known image types:
if (strpos($file_name, '.') === false &&
preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
$file_name .= '.'.$matches[1];
}
//Ensure that we don't have disallowed characters and add a unique id just to ensure that the file name will be unique
$file_name = substr(uniqid(),-5).'-'.preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name);
return $file_name;
}
$file_name = substr(uniqid(),-5).'-'.preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name);
Posted 29 October 2012 - 18:51 PM
$file_name = sha1(date()).'.'.substr(strrchr($file_name,'.'), 1);
Posted 29 October 2012 - 19:04 PM
Thanks for your answer, try what you sent me does not work, that is not what I'm doing wrong. Please help me.
Thanks.
Posted 29 October 2012 - 19:10 PM
for example :
$file_name = sha1(date()).'.'.substr(strrchr($file_name,'.'), 1);
[/quote]
[color=#282828][font=helvetica, arial, sans-serif]Hi Victor,[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]Thanks for your answer, try what you sent me does not work, that is not what I'm doing wrong. Please help me.[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]Thanks.[/font][/color]
Posted 29 October 2012 - 19:11 PM
private function trim_file_name($name, $type) {
// Remove path information and dots around the filename, to prevent uploading
// into different directories or replacing hidden system files.
// Also remove control characters and spaces (\x00..\x20) around the filename:
$file_name = trim(basename(stripslashes($name)), ".\x00..\x20");
// Add missing file extension for known image types:
if (strpos($file_name, '.') === false &&
preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
$file_name .= '.'.$matches[1];
}
//Ensure that we don't have disallowed characters and add a unique id just to ensure that the file name will be unique
// $file_name = '123456'.substr(uniqid(),-5).'-'.preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name);
$file_name = sha1(date()).'.'.substr(strrchr($file_name,'.'), 1);
return $file_name;
}
result : da39a3ee5e6b4b0d3255bfef95601890afd80709.jpg
Posted 29 October 2012 - 19:14 PM
Posted 29 October 2012 - 19:18 PM
Posted 29 October 2012 - 19:19 PM
Posted 29 October 2012 - 19:23 PM
Posted 29 October 2012 - 19:31 PM
Posted 29 October 2012 - 20:22 PM
Posted 29 October 2012 - 21:55 PM
I try in Ubuntu, and working perfect. Thanks. A last question, when he says he needs to encrypt a file, this is the right way.
Thanks.
Posted 29 October 2012 - 22:05 PM
A last question, when he says he needs to encrypt a file, this is the right way.
sorry, i don't understand this question.
Posted 29 October 2012 - 22:07 PM
Posted 29 October 2012 - 22:24 PM
it's better:
$file_name = sha1(microtime().$_SERVER['REMOTE_ADDR']).'.'.substr(strrchr($file_name,'.'), 1);
if you want to encrypt the contents of the file you need to do different way.
sorry, I'm bad in English.
Posted 29 October 2012 - 22:57 PM
Posted 29 October 2012 - 23:02 PM
Posted 29 October 2012 - 23:03 PM
Posted 29 October 2012 - 23:04 PM