• 15-11-2023, 21:27:59
    #1
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Merhabalar ben dosyayı şifreli bir şekilde sunucuya ve sqle yüklüyorum fakat dosyayı indirmeye çalıştığımda Arşiv biçimi bozuk diyor
    Zip,php,html dosyalarını açıyor fakat rar dosyasını açmıyor

    Konu çözülmüştür kilitlenebilir.
  • 15-11-2023, 21:41:59
    #2
    <?php
    require_once "inc/config/config.php";
    
    function upload($file, $path) {
        global $db, $users;
    
    
        $key = bin2hex(random_bytes(16));
        $iv = random_bytes(16);
    
    
        $fileContent = file_get_contents($file['tmp_name']);
        $encryptedContent = openssl_encrypt($fileContent, 'AES-256-CBC', $key, 0, $iv);
        file_put_contents($file['tmp_name'], $encryptedContent);
    
        $file['name'] = pathinfo($file['name']);
    
        $insert_array = [
            "upload_name" => $file['name']['filename'],
            "upload_extension" => $file['name']['extension'],
            "upload_date" => time(),
            "upload_user_id" => $users['user_id'],
            "upload_path" => $path,
            "upload_iv" => bin2hex($iv), // Hex formatında kaydetmek daha uygun
            "upload_key" => $key
        ];
    
        $insert = $db->insert("upload", $insert_array);
    
        $file['new-name'] = base64_encode($insert . "-" . $users['user_id'] . "-" . time()) . ".txt";
    
        move_uploaded_file($file['tmp_name'], $path . $file['new-name']);
    }
    
    function download($id) {
        global $db, $users;
    
        $upload = $db->select("upload", "*", ["upload_id" => $id]);
    
        if ($db->num_rows($upload)) {
            $upload = $db->fetch($upload, false);
            $filename = base64_encode($upload['upload_id'] . "-" . $upload['upload_user_id'] . "-" . $upload['upload_date']);
            $path = $upload['upload_path'];
    
            $fileContent = file_get_contents($path . $filename . ".txt");
    
            $decodedFile = openssl_decrypt($fileContent, 'AES-256-CBC', $upload['upload_key'], 0, hex2bin($upload['upload_iv']));
    
            $downloadFileName = "indirilen_dosya." . $upload['upload_extension'];
    
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . $downloadFileName . '"');
    
            echo $decodedFile;
            exit;
        } else {
            return "Hata! Böyle Bir Dosya Yok";
        }
    }
    
    if ($_FILES) {
        upload($_FILES['file'], "upload/test/");
    }
    
    if (isset($_GET['download'])) {
        echo download($_GET['download']);
    } else {
        ?>
        <form enctype="multipart/form-data" action="" method="POST">
            <input type="file" name="file">
            <button type="submit">Gönder</button>
        </form>
    <?php
    }
    ?>
  • 15-11-2023, 21:45:07
    #3
    wisex adlı üyeden alıntı: mesajı görüntüle
    <?php
    require_once "inc/config/config.php";
    
    function upload($file, $path) {
        global $db, $users;
    
    
        $key = bin2hex(random_bytes(16));
        $iv = random_bytes(16);
    
    
        $fileContent = file_get_contents($file['tmp_name']);
        $encryptedContent = openssl_encrypt($fileContent, 'AES-256-CBC', $key, 0, $iv);
        file_put_contents($file['tmp_name'], $encryptedContent);
    
        $file['name'] = pathinfo($file['name']);
    
        $insert_array = [
            "upload_name" => $file['name']['filename'],
            "upload_extension" => $file['name']['extension'],
            "upload_date" => time(),
            "upload_user_id" => $users['user_id'],
            "upload_path" => $path,
            "upload_iv" => bin2hex($iv), // Hex formatında kaydetmek daha uygun
            "upload_key" => $key
        ];
    
        $insert = $db->insert("upload", $insert_array);
    
        $file['new-name'] = base64_encode($insert . "-" . $users['user_id'] . "-" . time()) . ".txt";
    
        move_uploaded_file($file['tmp_name'], $path . $file['new-name']);
    }
    
    function download($id) {
        global $db, $users;
    
        $upload = $db->select("upload", "*", ["upload_id" => $id]);
    
        if ($db->num_rows($upload)) {
            $upload = $db->fetch($upload, false);
            $filename = base64_encode($upload['upload_id'] . "-" . $upload['upload_user_id'] . "-" . $upload['upload_date']);
            $path = $upload['upload_path'];
    
            $fileContent = file_get_contents($path . $filename . ".txt");
    
            $decodedFile = openssl_decrypt($fileContent, 'AES-256-CBC', $upload['upload_key'], 0, hex2bin($upload['upload_iv']));
    
            $downloadFileName = "indirilen_dosya." . $upload['upload_extension'];
    
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="' . $downloadFileName . '"');
    
            echo $decodedFile;
            exit;
        } else {
            return "Hata! Böyle Bir Dosya Yok";
        }
    }
    
    if ($_FILES) {
        upload($_FILES['file'], "upload/test/");
    }
    
    if (isset($_GET['download'])) {
        echo download($_GET['download']);
    } else {
        ?>
        <form enctype="multipart/form-data" action="" method="POST">
            <input type="file" name="file">
            <button type="submit">Gönder</button>
        </form>
    <?php
    }
    ?>
    Cevabınız için teşekkür ederim hocam fakat hala aynı hatayı alıyorum sadece .rar dosyalarında bu problemi yaşıyorum
  • 15-11-2023, 21:47:00
    #4
    Webiay adlı üyeden alıntı: mesajı görüntüle
    Cevabınız için teşekkür ederim hocam fakat hala aynı hatayı alıyorum sadece .rar dosyalarında bu problemi yaşıyorum

    <?php
    require_once "inc/config/config.php";
    
    function upload($file, $path) {
        global $db, $users;
    
    
        $key = bin2hex(random_bytes(16));
        $iv = random_bytes(16);
    
    
        $fileContent = file_get_contents($file['tmp_name']);
        $encryptedContent = openssl_encrypt($fileContent, 'AES-256-CBC', $key, 0, $iv);
        file_put_contents($file['tmp_name'], $encryptedContent);
    
        $file['name'] = pathinfo($file['name']);
    
        $insert_array = [
            "upload_name" => $file['name']['filename'],
            "upload_extension" => $file['name']['extension'],
            "upload_date" => time(),
            "upload_user_id" => $users['user_id'],
            "upload_path" => $path,
            "upload_iv" => bin2hex($iv), 
            "upload_key" => $key
        ];
    
        $insert = $db->insert("upload", $insert_array);
    
        $file['new-name'] = base64_encode($insert . "-" . $users['user_id'] . "-" . time()) . ".txt";
    
        move_uploaded_file($file['tmp_name'], $path . $file['new-name']);
    }
    
    function download($id) {
        global $db, $users;
    
        $upload = $db->select("upload", "*", ["upload_id" => $id]);
    
        if ($db->num_rows($upload)) {
            $upload = $db->fetch($upload, false);
            $filename = base64_encode($upload['upload_id'] . "-" . $upload['upload_user_id'] . "-" . $upload['upload_date']);
            $path = $upload['upload_path'];
    
            $fileContent = file_get_contents($path . $filename . ".txt");
    
            $decodedFile = openssl_decrypt($fileContent, 'AES-256-CBC', $upload['upload_key'], 0, hex2bin($upload['upload_iv']));
    
            $downloadFileName = "indirilen_dosya." . $upload['upload_extension'];
    
            // ZipArchive sınıfını kullanarak rar dosyası oluşturun
            $zip = new ZipArchive();
            $zipFileName = $path . $filename . ".rar";
    
            if ($zip->open($zipFileName, ZipArchive::CREATE) === TRUE) {
                $zip->addFromString($downloadFileName, $decodedFile);
                $zip->close();
    
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename="' . basename($zipFileName) . '"');
                readfile($zipFileName);
    
                // Rar dosyasını sildikten sonra çıkış yapın
                unlink($zipFileName);
                exit;
            } else {
                return "Hata! Rar dosyası oluşturulamadı.";
            }
        } else {
            return "Hata! Böyle Bir Dosya Yok";
        }
    }
    
    if ($_FILES) {
        upload($_FILES['file'], "upload/test/");
    }
    
    if (isset($_GET['download'])) {
        echo download($_GET['download']);
    } else {
        ?>
        <form enctype="multipart/form-data" action="" method="POST">
            <input type="file" name="file">
            <button type="submit">Gönder</button>
        </form>
    <?php
    }
    ?>
  • 15-11-2023, 21:54:50
    #5
    Teşekkür ederim bir sorum daha olacaktı yardım ederseniz sevnirim.İndirilen rar dosyasının ismini değiştirebilirmiyiz peki
  • 15-11-2023, 21:58:50
    #6
    Kimlik doğrulama veya yönetimden onay bekliyor.
    $downloadFileName = "indirilen_dosya." . $upload['upload_extension']; bundan