0

I need to extract rar file for my custom import extension.

i have used shell_exec() and exec("unzip/path/images.rar", $result, $returnval); but not working.

Any one knows how to extract rar file using SSH+php

4
  • OS on the server ? Commented Mar 28, 2017 at 6:48
  • Linux On Server Commented Mar 28, 2017 at 6:48
  • unrar is installed on the server? Commented Mar 28, 2017 at 6:49
  • Not now is this require ? Commented Mar 28, 2017 at 6:50

2 Answers 2

2

For Debian or Ubuntu Linux use apt-get

For Fedora Linux / CentOS / RHEL use yum

Install unrar on server

sudo apt-get install unrar

for zip file install unzip

sudo apt-get install unzip

then try

exec("unrar unzip/path/images.rar");

for zip

exec("unzip path/images.zip");
14
  • hi can you please give me suggestion for zip also ? @gopal patel Commented Mar 28, 2017 at 6:55
  • find updated answer @denishvachhani Commented Mar 28, 2017 at 6:57
  • can you please specify how to use target to destination path in this ? Commented Mar 28, 2017 at 6:59
  • 1
    @GopalPatel perfect just replace apt-get to yum in centos Commented Mar 28, 2017 at 6:59
  • 1
    @MurtuzaZabuawala yeah updated sirji ;) Commented Mar 28, 2017 at 7:02
1

Did you try running the rar x archive.rar command inside shell_exec().

shell_exec('rar x path/to/rar/file/filename.rar');

Make sure that path of the rar file is correct.

If the file is in the same folder where your php file is then you can give the filename without giving any path.

First, check if rar is installed in your Linux system.

if not installed, then you can run the following command -

sudo apt-get install rar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.