PHP decompression still does not .. Solve the problem of uploading a compressed package in PHP. I can unzip it. How can I rename the file while extracting the file and put it in another directory? Please kindly advise. Decompress the program $ zip & nbsp ;=& nbsp; zip_open ("/php/test/test.zip"); if & nbsp; ($ zip) & nbsp; {PHP does not extract files .. Solution
Upload a compressed package in PHP and I can unzip it.
How can I rename the file while extracting the file and put it in another directory?
Please kindly advise.
Decompress the program
$ Zip = zip_open ("/php/test/test.zip ");
If ($ zip ){
While ($ zip_entry = zip_read ($ zip )){
$ Fp = fopen ("/php/". zip_entry_name ($ zip_entry), 'w ');
If (zip_entry_open ($ zip, $ zip_entry, "r ")){
$ Buf = zip_entry_read ($ zip_entry, zip_entry_filesize ($ zip_entry ));
Fwrite ($ fp, '$ buf ');
Zip_entry_close ($ zip_entry );
Fclose ($ fp );
}
}
Zip_close ($ zip );
}
Add the rename function in the middle and save it to another directory ....
Zip_entry_name ($ zip_entry) is the file name in the package.
You can use the string function to process the object name.
Array is used in echo "zip_entry_name ($ zip_entry )".
Function zip_entry_name (& $ res)
{
If (! $ Res) return false;
Return $ res ['name'];
}
Solve the problem again... I really cannot do it... Share:
------ Solution --------------------
Your code includes $ fp = fopen ("/php/". zip_entry_name ($ zip_entry), 'w ');
How can we say that zip_entry_name ($ zip_entry) returns an array?
------ Solution --------------------
Echo zip_entry_name ($ zip_entry );
What?
------ Solution --------------------
In your code
$ Fp = fopen ("/php/". zip_entry_name ($ zip_entry), 'w'); // change it to the name of the file you need.
If (zip_entry_open ($ zip, $ zip_entry, "r ")){
$ Buf = zip_entry_read ($ zip_entry, zip_entry_filesize ($ zip_entry); // This is the file in the Read package
Fwrite ($ fp, '$ buf ');
------ Solution --------------------
Window environment?
Open a file in binary mode
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service