Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ctaljaardt's avatar

How to zip and upload files?

Hello.

So i want to have a download section but the downloads will contain malicious stuff in them and i dont want it to be detected by google or osmething as my website containing malware.

So what i want to do it this

user uploads malware -> laravel archives the file with a password -> laravel then uploads the zip to amazon s3.

I know ho wto do the uploading and stuff to amazon s3, i just dont know how to zip the file with a password when using laravel.

Does anyone have any idea's

0 likes
4 replies
ctaljaardt's avatar

@dfaux you are right about that but it doesnt allow you to password protect archives only decompress password protected archives.

"This function only sets the password to be used to decompress the archive; it does not turn a non-password-protected ZipArchive into a password-protected ZipArchive."

ctaljaardt's avatar

I have this which is working i think except when i try to upload it now.

    public function uploadfile(Request $request, Filesystem $filesystem)
    {
        $newname = str_random(32);
        $password = str_random(20);
        $file = Input::file('file');
        shell_exec('7z a -p ' . $password . ' -r ' . '/home/ubuntu/temp/' . $newname . '.7z ' . $file);
        $newpath = "/home/ubuntu/temp/" . $newname . ".7z";
        $filesystem->put('/downloads/malware/' . $newname . ".7z", file_get_contents($newpath));
        $filesystem->setVisibility('/downloads/malware/' . $newname . ".7z", 'public');
        return redirect()->back();
    }

I get this issue http://cl.ly/image/3M3L3o1B2i3E

davidfaux's avatar

Does the /home/ubuntu/temp folder exist and does www-data have access to the folder? You could use a folder within the storage directory to do this as well:

if( ! is_dir(storage_path('temp'))
{
    mkdir(storage_path('temp'));
}

$newname = str_random(32);
$password = str_random(20);
$newpath = storage_path("temp/{$newname}.7z ");
$file = Input::file('file');

shell_exec('7z a -p ' . $password . ' -r ' . $newpath . $file);

$filesystem->put('/downloads/malware/' . $newname . ".7z", file_get_contents($newpath));
$filesystem->setVisibility('/downloads/malware/' . $newname . ".7z", 'public');
return redirect()->back();
1 like

Please or to participate in this conversation.