PHP decompression still does not .. Solution-php Tutorial

Source: Internet
Author: User
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 = 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...


Reply to discussion (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?

Echo "[zip_entry_name ($ zip_entry)]"; this [zip_entry_name (Array)]
Echo "[$ zip_entry]"; this [Array]

Function zip_entry_name (& $ res)
{
If (! $ Res) return false;
Return $ res ['name'];
}

Echo zip_entry_name ($ zip_entry );
What?

Come out, haha
There is another problem... I renamed it with substr and

1. Where can I set the Directory of the files to be decompressed?
2. Where can I replace the original file with my desired name?

Continue to ask for advice...

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 ');

Boss, do you have any other contact information ....
I found that all the extracted files are saved with only one file name... The image is not displayed ....

I echo $ buf can display 20 lines of garbled characters on the webpage .. It should be of good size, isn't it fwrite .. Or encoding format?

Window environment?
Open a file in binary mode

Linux.
I can run it again in my own directory.
There is only a file name under the public, and the image cannot be opened...

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.