Unzip file using PHP that was zipped and uploaded using Java Android

347 views Asked by At

I am trying to unzip a file that was zipped and uploaded using Java Android. Unluckily, I was not able to unzip it. Is there an issue there? I have tried searching through Google and this forum how to unzip files and there were a lot of answers but when I tried them, it's not working on mine.

Scenario:

a. Click a button in Android app to zip all CSV files. Then upload the zipped file. (I am currently using WAMP localhost).

b. Unzip the uploaded file.

c. Insert data to the table.

Currently, with the code that I have, I am able to zip and upload the file. Problem arises during the unzipping. I cannot unzip the file.

Current code:

//Upload the file
$file_path = "ZipFiles/";     
$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
    echo "success";
} else{
    echo "fail";
}


//Unzip the uploaded file
$zip = new ZipArchive;
$zip->open('myUpload.zip');
$zip->extractTo('UnzipFiles/');
$zip->close(); 
1

There are 1 answers

0
user3201441 On BEST ANSWER

Maybe somebody will encounter this problem, that is why I'll be posting the workaround that I have found. Thanks to this site, I successfully unzip the file.

//Upload the file
$file_path = "ZipFiles/";     
$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
    echo "success";
    $zip = new ZipArchive();
    $zip->open($file_path);
    $zip->extractTo("UnzipFiles/");
    $zip->close(); 
} else{
    echo "fail";
}