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...