我尝试加密我的文件,然后使用move_upload_file函数移动我的文件。 如果没有加密功能,我可以上传我的文件。 但是我的问题是我需要它加密我的文件然后上传。 有人知道这个问题吗?请帮助。...
$newname = dirname(__FILE__).'/upload/'.$filename;
if (!file_exists($newname)) {
$ALGORITHM = 'AES-128-CBC';
$IV = '12dasdq3g5b2434b';
$password = '123456';
$contenuto = file_get_contents($_FILES['uploaded_file']['tmp_name']);
$contenuto = openssl_encrypt($contenuto, $ALGORITHM, $password, 0, $IV);
$filename = $filename . '.crypto';
if (move_uploaded_file($contenuto,$newname)) {
echo "It's done! The file has been saved.";
} else {
echo "Error: A problem occurred during file upload!";
}
} else {
echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
}
答案 0 :(得分:1)
未测试 您需要使用file_put_contents作为返回的字符串
$newname = dirname(__FILE__).'/upload/'.$_FILES['uploaded_file']['name'].'.crypto';
$tempfile = $_FILES['uploaded_file']['tmp_name'];
if (!file_exists($newname)) {
$ALGORITHM = 'AES-128-CBC';
$IV = '12dasdq3g5b2434b';
$password = '123456';
file_put_contents($tempfile, openssl_encrypt(file_get_contents($tempfile), $ALGORITHM, $password, 0, $IV));
if (move_uploaded_file($tempfile,$newname)) {
echo 'It\'s done! The file has been saved.';
} else {
echo 'Error: A problem occurred during file upload!';
}
} else {
echo 'Error: File '.$_FILES['uploaded_file']['name'].' already exists';
}
答案 1 :(得分:0)
快速浏览文档显示https://www.php.net/manual/en/function.openssl-encrypt.php openssl_encrypt返回一个加密的字符串,而不是文件。您需要将结果保存到文件中,然后将其移动到新的目的地。