[PHP] Upload encrypt image

Davide Cat

Nuovo Utente
5 Lug 2017
1
0
1
33
Ciao ragazzi,
Sto provando a caricare un immagine ma non riesco a cifrarla utilizzando il metodo openssl_encrypt. Qualcuno saprebbe aiutarmi?

// DEFINE our cipher
define('AES_256_CBC', 'aes-256-cbc');
// Generate a 256-bit encryption key
// This should be stored somewhere instead of recreating it each time
$encryption_key = openssl_random_pseudo_bytes(32);
// Generate an initialization vector
// This *MUST* be available for decryption as well
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(AES_256_CBC));


$user = $_SESSION['username'];
$directorypath = "uploads/". $user; //specifies the directory where the file is going to be placed
mkdir($directorypath, 0777); //create directory

$target_path = "$directorypath/";
$target_path = $target_path . basename( $_FILES['fileToUpload']['name']);

$uploadOk = 1;

$imageFileType = pathinfo($directorypath,PATHINFO_EXTENSION);

$data = $_FILES["fileToUpload"]["tmp_name"];
// Encrypt $data using aes-256-cbc cipher with the given encryption key and
// our initialization vector. The 0 gives us the default options, but can
// be changed to OPENSSL_RAW_DATA or OPENSSL_ZERO_PADDING
$encrypted = openssl_encrypt($data, AES_256_CBC, $encryption_key, 0, $iv);

// If we lose the $iv variable, we can't decrypt this, so:
// - $encrypted is already base64-encoded from openssl_encrypt
// - Append a separator that we know won't exist in base64, ":"
// - And then append a base64-encoded $iv
$encrypted = $encrypted . ':' . base64_encode($iv);

if(move_uploaded_file($encrypted, $target_path)) {
echo "The file ". basename( $_FILES['fileToUpload']['name'])." has been uploaded";
}else{
echo "There was an error uploading the file, please try again!";
}
 
Discussioni simili
Autore Titolo Forum Risposte Data
L Upload di un'immagine all'interno di un database usando php PHP 6
S Problemi con modulo upload video php (help!) PHP 0
S [PHP] Upload stesso file PHP 14
F [PHP] Informazioni upload PHP 11
G [PHP] upload file in server: percorso cartella PHP 2
M Upload 4 file php PHP 11
D [PHP] Upload intera cartella PHP 2
felino [PHP] Uploadify: upload immagini PHP 0
M [PHP] Nome file, upload e rinominare PHP 2
M [PHP] upload di un file esistente overwrite PHP 1
N [PHP] Test per l'upload di file attraverso un bot Telegram PHP 2
L [PHP] problema con upload e javascript (upload multiplo) Javascript 2
L [PHP] upload con errore PHP 2
V [PHP] Upload Excel in db PHP 0
jailbait [PHP] Upload immagine e stampa a schermo PHP 0
G PHP upload dati ed immagine PHP 7
F [PHP] Validare form prenotazione appuntamento tattoo con upload image PHP 0
C [PHP] Problema upload file (multiplo) PHP 1
P [PHP] Upload multiplo PHP 4
N [PHP] Problema upload immagini wordpress PHP 2
S [PHP] Upload file... PHP 6
giancadeejay [PHP] Aggiornare DB tramite UPLOAD file .csv PHP 39
MarcoGrazia [PHP] Upload e successiva visualizzazione immagini in DB PHP 3
V [PHP] upload di file in cartella e sua sicurezza PHP 137
S PHP: Aiuto con upload immagini che si auto tuotano PHP 24
C [PHP] Upload immagine in un form con target _blank: non funziona PHP 7
V File upload.php della guida, ma ha un errore PHP 8
A Upload multiplo di immagini in PHP PHP 3
francesco7 [Problema] esecuzione script Upload file in php PHP 0
I upload file php / javascript / mysql PHP 0
R upload file php PHP 5
L [php] upload controllo dimensione immagine PHP 8
F upload foto in php?????? PHP 2
R upload e ridimensionamento immagini in php PHP 0
R upload e ridimensionamento immagini in php PHP 1
L [PHP] Upload immagini e ridimensionamento automatico PHP 9
N [RISOLTO] Upload jpeg e pdf in folder (PHP) PHP 16
K [PHP] multi upload immagine da form PHP 60
L Passare ad uno script PHP i dati di un form incluso l'upload di un'immagine Ajax 0
N problema script php mysql multi upload immagini PHP 31
helpdesk Gif agli eventi di php Upload PHP 6
L [PHP e FTP upload] controllo file allegato PHP 6
neo996sps [PHP + MySQL + Server Linux] Upload semi riuscito e query non eseguite PHP 2
novello88 PHP upload file PHP 1
Y [PHP/MySQL] Upload PDF PHP 3
O PHP ecommerce > da un sito funzionante > duplicazione riuscita ma non upload immagini PHP 19
B [PHP - MySQL] Upload di un File PHP 6
B upload con resize in php PHP 5
M UPLOAD File in PhP PHP 3
SolidSnake4 miglior script per l'upload di immagini con php su DB PHP 5

Discussioni simili