I want to extract archive files (zip,rar,z7,gz,etc) from PHP. Because the passwords can contain special characters like ¡¿, and PHP exec does not support unicode characters (for some reason). I eneded up using a batch file as explained here php exec() in unicode mode?.
But, as lovely as windows 10 is, I can't seem to figure out how to extract an archive that has a single double quote as password...
"C:\Program Files\7-Zip\7z.exe" x "C:\Users\me\Desktop\25mb.rar" -o"C:\Users\me\Desktop\" -p"password here" -y
That is the default line to extract using 7zip. (note below) I have a file 25mb.bin stored in test.rar stored in 25mb.rar with password " (single double quote).
The error is:
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
Scanning the drive for archives:
1 file, 13312 bytes (13 KiB)
Extracting archive: C:\Users\me\Desktop\25mb.rar
--
Path = C:\Users\me\Desktop\25mb.rar
Type = Rar
Physical Size = 13312
Solid = -
Blocks = 1
Multivolume = -
Volumes = 1
ERROR: Data Error in encrypted file. Wrong password? : test.rar
Sub items Errors: 1
Archives with Errors: 1
Sub items Errors: 1
I tried:
-p" *
-p"" **
-p""" *
-p"""" **
-p"^"" * (default escape for CMD)
-p"\"" *
*: The line asks me if i want to overwrite, meaning that the -y is not executed but seen as part of the password.
**: Executes, but with error. The extracted file test.rar cannot be opened (is corrupted)
Note: This method has no problem whatsoever with ~`!@#$%^&()_+-={}[]|:;'<>?,./€¡¿*
Note: winRAR has a neat feature in which you can provide a file with a password, to use to extract, instead of providing a string. This however only works for RAR files(!) and is thus useless in my situation.
Example with rar:
file_put_contents( 'C:\Users\bunny\Desktop\pass.txt', $password );
exec( '"C:\\Program Files\\WinRAR\\winrar" e -ad -p "C:\\Users\\me\\Desktop\\25mb.rar" *.* "C:\\Users\\me\\Desktop\" < "C:\\Usersme\\Desktop\\pass.txt"', $extractStatus );