PHP UnRar.exe into a specific directory - php

Ive just found this script and it is exactly what im looking for, However how can i tell it to extract the files into a specific folder?
Here is the script
<?php
$winRAR = '"C:\Program Files\WinRAR\UnRAR.exe"';
$file="test.rar";
$do ="$winRAR e $file";
exec("$winRAR /?");
print_r($aOut);
exec($do,$aOut);
print_r($aOut);
?>
Im going to be extracting multiple files so i would like it to extract each archive into a a folder with the same name as the archive. So if the rar was called "Test" i want it to extract to a folder called /test/ and extract the files there?
Many Thanks in advance!

I suggest you to use the following command:
$do ="$winRAR x -ad $file $destinationPath";
Where $destinationPath is a destination path.
The "x" command will keep directory structure stored in archive in contrast with "e" command, which extracts files without subdirectories.
The "-ad" command line switch tells unrar to extract archive foo.rar to the $destinationPath/foo directory.
Command line commands and switches are listed in WinRAR help file, in section "Command line mode".

I think what you are trying to do may be easier using PHP's RAR extension. http://www.php.net/manual/en/book.rar.php

Related

How to unlink file from children dir of parent dir? PHP

I want to unlink an image file from children dir of a parent dir.
I developing this project in a director folder under my website (mysite/project) but when i complete the project i will move to another hosting package.
Whic code i need use for stable running in all directories?
I get this error:
Warning: unlink(../../images/urunler/deneme-urun.jpg): No such file or directory in /home/admin/public_html/eticaret/admin/includes/updateproduct.php on line 120
My folder structure:
click here to see my folder structure
$delete = unlink("../../images/products/".$img);
Before running unlink() command you can check the existence of the file to get rid of such error
$path = "../../images/products/".$img;
if (file_exists(path)) {
unlink($path)
}
Better is using the full directory path (absolute path). An example, let your project structure is
and your unlinking code is in script.php, then your can get full absolute path the following way
$path = __DIR__ . "/../../images/products/{$img}";
if (file_exists(path)) {
unlink($path)
}
Thanks for all answers.
I have a fault on this topic.
Image name is xxx.jpg in my database but xxx.jpeg in the folder.
but there is an interesting situation: if you have an image as .jpeg format, you can open on browser as .jpg format.
I've tried a lot of methods to solve the above error, but I've found that.
I using chrome browser now.
So i solved my problem yet :)
as the script is run from "public_html/eticaret/admin/includes/" you need to .. traverse back 3 directories to get to public_html which is a common ancestor folder for both image and script
according to your directory image your images are in public_html/myproject/images/products/ and according to error detailed in your comment you are trying to delete from images/urunler/ I assume urunler is the actual project name.
if the folder containg your images is urunler try $delete = unlink("../../../images/urunler/".$img);
if the container folder is products try $delete = unlink("../../../images/products/".$img);
if that fails try using an absolute path instead of a relative path.

PHP ZipArchive can't read more then 21797 files inside

I need to extract from zip file data.zip only one file for example 188139.xml
File contains folder with more than 88000 files. But after open - it shows me 21797 files and can't open file with big index (which is truly there). But opens 1.xml, 200.xml etc.
So it looks like limitation. Is there any suggestions how to open needed file?
Looks like it a bug of library. Fixed with alternative use of execute() function.

ci zip encoding class not working properly

I want to crate a zip file and download it.
So my code is as follow;
Since i am using ci zip encoding class
my folder structure is like
c:/xampp/htdocs/gallery/print/oid_1/1.jpg,2.jpg,3.jpg
My code
$path = getcwd().'/print/oid_1/';
$this->zip->read_dir($path,FALSE);
// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('oid_1.zip');
Here is my problem,
l C:\Users\instinctclassic\Downloads\Compressed\oid_1.zip: The archive is either in unknown format or damaged so what does this means -does it means it was mistaken while making zip file or it was mistaken while downloading.For downloading mistake i have downloaded the zip file many time enough to be sure.
2 I repaired the downloaded zip file(oid_1) and extract it but the extracted folder structure is not ignored before the oid_1 folder as said in ci zip encoding class tutorial
$this->zip->read_dir($path, FALSE);
//This will create a ZIP with the folder "directory" inside, then all sub-folders stored correctly inside that, but will not include the folders /path/to/your.
3 Assuming my folder oid_1 already exists somewhere on server.
I know this question is previously asked but mine exist all the problem from making zip file to extracting.So i am sorry for this.
Thanks
Try directory path like this:
$path = getcwd().'\print\oid_1\';
this way path will be proper, because getcwd() will return you c:\xampp\htdocs\gallery

PHP working with files inside an archive

Is there a PHP supported way to work with an archive of files (.zip, .tar or any other archive) same way we work with a folders?
For example if in our root "/www/" directory there is an archive "/www/catalog.zip" that contains .php files, would it be possible to include this archive with PHP so that PHP would know what is inside the archive and if required to include a file (for example test.php that is inside the catalog.zip) we can do so without extracting the "catalog.zip" archive?
Not sure if something like this exists (of course it would be possible to build a application to do something like this, but it would be resource if done with PHP using extract read/remove)
or maybe there is something similar that can be used?
Perhaps something like ZipArchive::getStream together with stream_get_contents would get you the file content but I'm not sure how you'd include it - don't think php can include from stdin

Skip "root" directory when extracting using ZipArchive class?

I am attempting to use the ZipArchive class to unzip the contents of a zip containing a GitHub repository.
When you download a zip from GitHub, the zip contains a folder at the root of the zip named something like "project-2302392-20230"... Then within that folder are the actual contents of the repository.
Is it possible extract everything within that project folder without extracting the folder itself?
Here's one way to figure out the name of the unique top directory of the github zip archive.
use getArchiveComment() to get the ziparchive comment.
use strpos to strip away all characters except the first 7 and also add the git username and repo name like so '/USER-REPO-'.substr($comment, 0, 7);
You could also use regex, scandir, and a number of other ways.

Categories