Mas User
Mas User

Reputation: 166

Removing Zip Folder Using PHP

How can i remove or delete a zip folder using php code?

In my application i need to extract a zip folder after extaracting remove the zip folder. How can i do this?

I can extract or unzip the zipped folder using php code that will successed. But i dont know hot remove the zipped folder.

This is the code to extract zip folder:

$this->load->library('unzip');
$var = $this->unzip->extract('./folder/zip_foldername', './folder/newname');

Upvotes: 0

Views: 1677

Answers (4)

Quentin Pradet
Quentin Pradet

Reputation: 4771

If you want to use CodeIgniter's "standard library", then you could load the file helper, then delete the file with delete_files.

<?php
    $this->load->helper('file');
    delete_files('./folder/zip_foldername');
?>

Note: I'm using './folder/zip_foldername' since you also used this name in the first parameter of extract() which corresponds to the zip file.

If you actually want to delete a whole folder, then just pass TRUE to your to delete_files.

<?php
    $this->load->helper('file');
    delete_files('./folder/newname');
?>

Upvotes: 0

Akhil Thayyil
Akhil Thayyil

Reputation: 9403

Use unlink function in php

bool unlink ( string $filename [, resource $context ] )

<?php

unlink('urzipfile.zip');
?>

http://php.net/manual/en/function.unlink.php

Upvotes: 0

thecodeparadox
thecodeparadox

Reputation: 87073

try this:

unlink('url to zip');

Upvotes: 0

Jeff
Jeff

Reputation: 380

Use the unlink() function

http://www.php.net/manual/en/function.unlink.php

Edit: after reading your post again I'm not sure I understood. Did you mean to delete the zip file or the resulting folder containing all the extracted files? If the the latter then you would first need to loop through that directory and use unlink to delete all of the files then use rmdir() to delete the directory

http://php.net/manual/en/function.rmdir.php

Upvotes: 4

Related Questions